package com.fingard.dsp.bank.directbank.zyb02;

import java.io.File;
import java.io.IOException;
import java.math.BigDecimal;
import java.sql.Connection;
import java.util.*;

import com.dcfs.esc.ftp.client.FtpClientConfig;
import com.fingard.FGBiz;
import com.fingard.constant.DecimalFormat2;
import com.fingard.constant.Format;
import com.fingard.db.JDBCHelper;
import com.fingard.diagnostics.LogHelper;
import com.fingard.dsp.bank.directbank.PaymentState;
import com.fingard.dsp.bank.directbank.allinpay02.util.SybUtil;
import com.fingard.dsp.bank.directbank.bankInterface.IBatPayRec;
import com.fingard.dsp.bank.reqrespobj.ReqRespHeader;
import com.fingard.dsp.bank.reqrespobj.batpayrec.ReqBatPayRec;
import com.fingard.dsp.bank.reqrespobj.batpayrec.ReqQryBatPayRec;
import com.fingard.dsp.bank.reqrespobj.batpayrec.RetAtsBatPayRec;
import com.fingard.dsp.bank.reqrespobj.batpayrec.RetAtsQryBatPayRec;
import com.fingard.dsp.bank.reqrespobj.batpayrec.detail.RetAtsBatPayRecDetail;
import com.fingard.dsp.bank.reqrespobj.single.detail.ReqPayRecDetail;
import com.fingard.io.FileHelper;
import com.fingard.net.ConnState;
import com.fingard.text.StringHelper;
import com.fingard.util.DateHelper;
import com.fingard.xml.XElement;
import com.fingard.xml.XmlTextReader;
import com.fingard.xml.XmlTextWriter;
import com.kayak.api.Payment;

public class ZYB02BatPayRec extends ZYB02Base implements IBatPayRec {

    @Override
    public RetAtsBatPayRec d_9188_BatPay(ReqBatPayRec p_req9188) throws Exception {
        return null;
    }

    @Override
    public RetAtsQryBatPayRec d_9198_QryBatPay(ReqQryBatPayRec p_req9198) throws Exception {
        return null;
    }

    @Override
    public RetAtsBatPayRec d_1988_BatPay(ReqBatPayRec p_req1988) throws Exception {
        /**
         * 同行的批量付款分为：代发工资(一笔记账)，普通批量代发多笔记账(more)，普通批量代发一笔记账(one)
         */
        String commandCode = p_req1988.reqHeader.commandCode;
        if ("198801".equals(commandCode)) {//普通批量代发多笔记账(more)
            return d_198801_BatPay(p_req1988, "more");
        } else if ("198802".equals(commandCode)) {//代发工资(一笔记账)
            return d_198802_BatPay(p_req1988);
        } else if ("198803".equals(commandCode)) {//普通批量代发一笔记账(one)
            return d_198803_BatPay(p_req1988, "one");
        } else if ("198804".equals(commandCode)) {//跨行批量(一笔记账)
            return d_198804_BatPay(p_req1988);
        }
        return null;
    }

    public RetAtsBatPayRec d_198803_BatPay(ReqBatPayRec p_req1988, String accountMode) throws Exception {
        return d_198801_BatPay(p_req1988, accountMode);
    }

    public RetAtsQryBatPayRec d_199803_QryBatPay(ReqQryBatPayRec p_req1998) throws Exception {
        return d_199801_QryBatPay(p_req1998);
    }

    @Override
    public RetAtsQryBatPayRec d_1998_QryBatPay(ReqQryBatPayRec p_req1998) throws Exception {
        String commandCode = p_req1998.reqHeader.commandCode;
        if ("198801".equals(commandCode)) {
            return d_199801_QryBatPay(p_req1998);
        } else if ("198802".equals(commandCode)) {
            return d_199802_QryBatPay(p_req1998);
        } else if ("198803".equals(commandCode)) {
            return d_199803_QryBatPay(p_req1998);
        } else if ("198804".equals(commandCode)) {
            return d_199804_QryBatPay(p_req1998);
        }
        return null;
    }

    /**
     * 代发工资
     *
     * @param p_req1988
     * @return
     * @throws Exception
     */
    public RetAtsBatPayRec d_198802_BatPay(ReqBatPayRec p_req1988) throws Exception {
        String seqNumberStart = getBankConfig().getMapValueByKey("Sys_Head", "CONSUMER_ID") + reqHeader.corporation;
        //返回给ats的对象
        RetAtsBatPayRec retAts = new RetAtsBatPayRec(p_req1988.reqHeader);
        String busiCode = "";
        String bankBatchNo = "";
        String batchPurpose = "";
        //<editor-fold desc="1.查询代发工资协议号">
        ZYB02Header bankHeader = new ZYB02Header();
        bankHeader.SEQ_NO = seqNumberStart + reqHeader.reqSeqID + SybUtil.getValidatecode(2) + "01";
        bankHeader.TRAN_CODE = getBankConfig().getMapValueByKey("TRANS_CODE", "PROTOCOLQUERY");
        String transTime = p_req1988.reqHeader.transTime;
        bankHeader.TRAN_DATE = Format.Date10Format.format(DateHelper.convertToDateExtra(transTime));
        bankHeader.TRAN_TIMESTAMP = TIME12FORMAT.format(DateHelper.convertToDateExtra(transTime));
        bankHeader.USER_IP = getIpInfoMap(p_req1988.getOriReqXml()).get("userIP");
        bankHeader.SERVER_IP = getIpInfoMap(p_req1988.getOriReqXml()).get("serverIP");
        XmlTextWriter xmlWriter = new XmlTextWriter();
        xmlWriter.autoFormat = false;
        writeCommon(xmlWriter, bankHeader);
        xmlWriter.writeElementString("PayerAccountNo", p_req1988.ownAct);
        xmlWriter.writeElementString("PayerAccountName", p_req1988.ownActName);
        xmlWriter.writeElementString("OrgCode", p_req1988.payOrganizationCode);
        xmlWriter.writeEndElement();
        xmlWriter.writeEndDocument();
        String[] retStrArr = sendXmlToBank(xmlWriter.toXmlString());
        //解析银行返回
        if (retStrArr[0].length() == 0) {
            StringBuilder tmpSbMsg = new StringBuilder();
            XmlTextReader tmpBkReader = loadBankRespXmlReader(retStrArr[1], tmpSbMsg);
            if (tmpBkReader != null) {
                String ret_code = tmpBkReader.getFirstText("/Message/Head/_RejCode");
                if (ret_code != null && ret_code.equals(RET_CODE)) {
                    busiCode = tmpBkReader.getFirstText("/Message/Body/List/Map/BusiCode");
                }
            }
        }
        if (StringHelper.isNullOrEmpty(busiCode)) {
            WriteBankLogLn("查询代发工资协议号异常：" + retStrArr[0] + "\r\n" + retStrArr[1]);
            retAts.respCode = "0";
            retAts.respInfo = "查询代发工资协议号异常！";
            retAts.reqSeqID = p_req1988.reqBatchNO;
            retAts.transState = PaymentState.FAIL_Batch;
            retAts.payInfoCode = ConnState.FAIL + "-" + retAts.respInfo;
            retAts.writeRetToATS();
            return retAts;
        } else {
            WriteBankLogLn("查询到的代发工资协议号为：" + busiCode);
        }
        //</editor-fold>

        //<editor-fold desc="2.生成文件">
        int serialNumber = 0;
        StringBuilder fileContext = new StringBuilder();
        fileContext.append(p_req1988.totalNum).append(FILESEPARATOR).append(p_req1988.totalAmt).append(FILESEPARATOR + "\r\n");
        while (p_req1988.readRecord()) {
            //序号|账号|币种|交易金额|附言|中文名|英文名|性别|国籍|发证国家|签发机关|证件类型|证件号码|证件到期日|详细地址|固定电话|手机号
            //1|6228586909823232|CNY|100.00|memo|刘德华|liu1|M|01|中国|某某公安局|01|82012912190001010012|20200101|address|13801010101|13910101010|
            serialNumber++;
            StringBuilder row = new StringBuilder();
            row.append(serialNumber).append(FILESEPARATOR);//序号
            row.append(p_req1988.readedDetail.recAct).append(FILESEPARATOR);//账号
            row.append(convertCurToBank(p_req1988.readedDetail.payCur)).append(FILESEPARATOR);//币种
            row.append(p_req1988.readedDetail.payAmount).append(FILESEPARATOR);//交易金额
            row.append(p_req1988.readedDetail.askNumber).append(FILESEPARATOR);//附言:埋入流水号
            row.append(p_req1988.readedDetail.recName).append(FILESEPARATOR);//中文名
            row.append("").append(FILESEPARATOR);//英文名
            row.append("").append(FILESEPARATOR);//性别
            row.append("").append(FILESEPARATOR);//国籍
            row.append("").append(FILESEPARATOR);//发证国家
            row.append("").append(FILESEPARATOR);//签发机关
            row.append("").append(FILESEPARATOR);//证件类型
            row.append("").append(FILESEPARATOR);//证件号码
            row.append("").append(FILESEPARATOR);//证件到期日
            row.append("").append(FILESEPARATOR);//详细地址
            row.append("").append(FILESEPARATOR);//固定电话
            row.append("").append(FILESEPARATOR);//手机号
            row.append("\r\n");
            if (StringHelper.isNullOrEmpty(batchPurpose)) {
                //batchPurpose = p_req1988.readedDetail.purpose;
                batchPurpose = p_req1988.readedDetail.memo;
            }
            fileContext.append(row);
        }
        String batchNo = seqNumberStart + p_req1988.reqBatchNO;
        String fileName = busiCode + "_" + Format.Date8Format.format(DateHelper.convertToDateExtra(reqHeader.transTime)) + "_" + "4179901" + "_" + batchNo + ".txt";
        boolean uploadResult = false;
        if (fileContext.toString().length() > 0) {
            String fileContextStr = StringHelper.trimEnd(fileContext.toString(), "\r\n");
            uploadResult = fileUpload(fileContextStr, fileName, getBankConfig().getValueAsString("wageFilePath"), "GBK");
            if (!uploadResult) {
                retAts.respCode = "0";
                retAts.respInfo = "生成批量文件失败！";
                retAts.reqSeqID = p_req1988.reqBatchNO;
                retAts.transState = PaymentState.FAIL_Batch;
                retAts.payInfoCode = ConnState.FAIL + "-" + retAts.respInfo;
                retAts.writeRetToATS();
                return retAts;
            }
        } else {
            retAts.respCode = "0";
            retAts.respInfo = "没有获取到批量支付明细信息";
            retAts.reqSeqID = p_req1988.reqBatchNO;
            retAts.transState = PaymentState.FAIL_Batch;
            retAts.payInfoCode = ConnState.FAIL + "-" + retAts.respInfo;
            retAts.writeRetToATS();
            return retAts;
        }
        //</editor-fold>

        //<editor-fold desc="3.发送文件名得到批次号">
        bankHeader.SEQ_NO = seqNumberStart + reqHeader.reqSeqID + SybUtil.getValidatecode(2) + "02";
        bankHeader.TRAN_CODE = getBankConfig().getMapValueByKey("TRANS_CODE", "PAYWAGEFILE");
        bankHeader.USER_IP = getIpInfoMap(p_req1988.getOriReqXml()).get("userIP");
        bankHeader.SERVER_IP = getIpInfoMap(p_req1988.getOriReqXml()).get("serverIP");
        XmlTextWriter xmlWriterFile = new XmlTextWriter();
        xmlWriterFile.autoFormat = false;
        writeCommon(xmlWriterFile, bankHeader);
        xmlWriterFile.writeElementString("BusiCode", busiCode);
        //xmlWriterFile.writeElementString("FileName", getBankConfig().getValueAsString("remoteFilePath")+"/"+fileName);
        xmlWriterFile.writeElementString("FileName", fileName);
        xmlWriterFile.writeElementString("TotalAmount", p_req1988.totalAmt);
        xmlWriterFile.writeElementString("TotalCount", p_req1988.totalNum);
        xmlWriterFile.writeEndElement();
        xmlWriterFile.writeEndDocument();
        String[] retStrArrFile = sendXmlToBank(xmlWriterFile.toXmlString());
        //解析银行返回
        if (retStrArrFile[0].length() == 0) {
            StringBuilder tmpSbMsg = new StringBuilder();
            XmlTextReader tmpBkReader = loadBankRespXmlReader(retStrArrFile[1], tmpSbMsg);
            if (tmpBkReader != null) {
                String ret_code = tmpBkReader.getFirstText("/Message/Head/_RejCode");
                if (ret_code != null && ret_code.equals(RET_CODE)) {
                    bankBatchNo = tmpBkReader.getFirstText("/Message/Body/BatchNo");
                }
            }
        }
        if (StringHelper.isNullOrEmpty(bankBatchNo)) {
            WriteBankLogLn("没有得到银行返回的批次号：" + retStrArrFile[0] + "\r\n" + retStrArrFile[1]);
            retAts.respCode = "0";
            retAts.respInfo = "没有得到银行返回的批次号";
            retAts.reqSeqID = p_req1988.reqBatchNO;
            retAts.transState = PaymentState.FAIL_Batch;
            retAts.payInfoCode = ConnState.FAIL + "-" + retAts.respInfo;
            retAts.writeRetToATS();
            return retAts;
            //throw new Exception("没有得到银行返回的批次号："+retStrArrFile[0]+"\r\n"+retStrArrFile[1]);
        } else {
            WriteBankLogLn("银行返回的批次号为：" + bankBatchNo);
        }
        //</editor-fold>
        StringBuilder errMsg = new StringBuilder();
        //bankBatchNo是批次号，busiCode是协议号
        boolean saveResult = saveReqSeqIDMapping(reqHeader.bankCode, reqHeader.transType, new Date(), seqNumberStart + p_req1988.reqBatchNO, bankBatchNo, busiCode, errMsg);
        if (!saveResult) {
            WriteBankLogLn("保存银行返回的批次号和协议号失败：" + errMsg.toString());
            retAts.respCode = "0";
            retAts.respInfo = "保存银行返回的批次号和协议号失败";
            retAts.reqSeqID = p_req1988.reqBatchNO;
            retAts.transState = PaymentState.FAIL_Batch;
            retAts.payInfoCode = ConnState.FAIL + "-" + retAts.respInfo;
            retAts.writeRetToATS();
            return retAts;
            //throw new Exception("保存银行返回的批次号和协议号失败："+errMsg.toString());
        }
        //<editor-fold desc="4.上送批次号">
        bankHeader.SEQ_NO = seqNumberStart + reqHeader.reqSeqID + SybUtil.getValidatecode(2) + "03";
        bankHeader.TRAN_CODE = getBankConfig().getMapValueByKey("TRANS_CODE", "PAYWAGEBATCHNO");
        bankHeader.USER_IP = getIpInfoMap(p_req1988.getOriReqXml()).get("userIP");
        bankHeader.SERVER_IP = getIpInfoMap(p_req1988.getOriReqXml()).get("serverIP");
        XmlTextWriter xmlWriterBatch = new XmlTextWriter();
        xmlWriterBatch.autoFormat = false;
        writeCommon(xmlWriterBatch, bankHeader);
        xmlWriterBatch.writeElementString("BusiCode", busiCode);
        xmlWriterBatch.writeElementString("TotalAmount", p_req1988.totalAmt);
        xmlWriterBatch.writeElementString("TotalCount", p_req1988.totalNum);
        xmlWriterBatch.writeElementString("BatchNo", bankBatchNo);
        xmlWriterBatch.writeElementString("Remark", batchPurpose);//批次的用途,批次中每一笔都是一样的，随便取一个
        xmlWriterBatch.writeEndElement();
        xmlWriterBatch.writeEndDocument();
        String[] retStrArrBatch = sendXmlToBank(xmlWriterBatch.toXmlString());
        //解析银行返回
        if (retStrArrBatch[0].length() == 0) {
            StringBuilder tmpSbMsg = new StringBuilder();
            XmlTextReader tmpBkReader = loadBankRespXmlReader(retStrArrBatch[1], tmpSbMsg);
            if (tmpBkReader != null) {
                String ret_code = tmpBkReader.getFirstText("/Message/Head/_RejCode");
                String ret_msg = tmpBkReader.getFirstText("/Message/Head/_RejMsg");
                String process_state = tmpBkReader.getFirstText("/Message/Head/_ProcessState");
                retAts.respCode = "0";
                retAts.reqSeqID = p_req1988.reqBatchNO;
                retAts.respInfo = ret_msg;
                retAts.transState = process_state;
                retAts.payInfoCode = ret_code + "-" + ret_msg;
            } else {
                retAts.respCode = "-1";
                retAts.respInfo = tmpSbMsg.toString();
                /*retAts.writeRespCode("-1");
                retAts.writeRespInfo(tmpSbMsg.toString());*/
            }
        } else {
            retAts.respCode = "-1";
            retAts.respInfo = retStrArrBatch[1];
            /*retAts.writeRespCode("-1");
            retAts.writeRespInfo(retStrArrBatch[1].toString());*/
        }
        //</editor-fold>
        retAts.writeRetToATS();
        return retAts;
    }

    /**
     * 代发工资状态查询
     *
     * @param p_req1998
     * @return
     * @throws Exception
     */
    public RetAtsQryBatPayRec d_199802_QryBatPay(ReqQryBatPayRec p_req1998) throws Exception {
        String seqNumberStart = getBankConfig().getMapValueByKey("Sys_Head", "CONSUMER_ID") + reqHeader.corporation;
        //返回ATS的对象
        RetAtsQryBatPayRec retAts = new RetAtsQryBatPayRec(p_req1998.reqHeader);
        try {
            //通用参数赋值
            ZYB02Header bankHeader = new ZYB02Header();
            bankHeader.SEQ_NO = seqNumberStart + reqHeader.transSeqID;
            bankHeader.TRAN_CODE = getBankConfig().getMapValueByKey("TRANS_CODE", "PAYWAGEQUERY");
            String transTime = p_req1998.reqHeader.transTime;
            bankHeader.TRAN_DATE = Format.Date10Format.format(DateHelper.convertToDateExtra(transTime));
            bankHeader.TRAN_TIMESTAMP = TIME12FORMAT.format(DateHelper.convertToDateExtra(transTime));
            bankHeader.USER_IP = getIpInfoMap(p_req1998.getOriReqXml()).get("userIP");
            bankHeader.SERVER_IP = getIpInfoMap(p_req1998.getOriReqXml()).get("serverIP");
            //发银行报文的XML对象
            XmlTextWriter xmlWriter = new XmlTextWriter();
            xmlWriter.autoFormat = false;
            //写入通用的头部节点
            writeCommon(xmlWriter, bankHeader);
            StringBuilder errMsg = new StringBuilder();
            //0.协议号 1.批次号
            List<String> bankBatchNumAndBusiCode = getBankBatchNumAndBusiCode(seqNumberStart + p_req1998.reqBatchNO, new Date(), errMsg);
            if (errMsg.length() > 0 || bankBatchNumAndBusiCode == null || bankBatchNumAndBusiCode.size() != 2) {
                throw new Exception("根据批次号查询银行批次号和协议号异常:" + errMsg);
            }
            xmlWriter.writeElementString("BusiCode", bankBatchNumAndBusiCode.get(0));
            xmlWriter.writeElementString("BatchNo", bankBatchNumAndBusiCode.get(1));
            //xmlWriter.writeElementString("QryBeginDate", "20290720");
            //xmlWriter.writeElementString("QryEndDate", "20290720");
            xmlWriter.writeElementString("QryBeginDate", Format.Date8Format.format(DateHelper.convertToDateExtra(p_req1998.bgnDate)));
            xmlWriter.writeElementString("QryEndDate", Format.Date8Format.format(DateHelper.convertToDateExtra(p_req1998.bgnDate)));
            //xmlWriter.writeElementString("QryEndDate", Format.Date8Format.format(DateHelper.convertToDateExtra("20330131")));
            xmlWriter.writeElementString("QryId", "0");
            xmlWriter.writeElementString("QryNum", p_req1998.totalNum);
            xmlWriter.writeElementString("SuccFlag", "9");

            xmlWriter.writeEndElement();
            xmlWriter.writeEndDocument();

            String[] tmpStrRet = sendXmlToBank(xmlWriter.toXmlString());
            if (tmpStrRet[0].length() == 0) {
                StringBuilder tmpSbMsg = new StringBuilder();
                XmlTextReader tmpBkReader = loadBankRespXmlReader(tmpStrRet[1], tmpSbMsg);

                if (tmpBkReader != null) {
                    String tmpStatus = tmpBkReader.getFirstText("/Message/Head/_RejCode");
                    String err_msg = tmpBkReader.getFirstText("/Message/Head/_RejMsg");
                    String ret_code = tmpBkReader.getFirstText("/Message/Body/List/Map/Xydm");
                    String tmpStatusText = tmpBkReader.getFirstText("/Message/Body/List/Map/Xyxx");
                    String resultFile = tmpBkReader.getFirstText("/Message/Body/List/Map/MbsRespFileName");
                    String CurstepFlag = tmpBkReader.getFirstText("/Message/Body/List/Map/CurstepFlag");
                    String Dealsts = tmpBkReader.getFirstText("/Message/Body/List/Map/Dealsts");
                    if (StringHelper.hasAnyChar(resultFile)) {
                        WriteBankLogLn("结果文件名为：" + resultFile);
                        //wget -d -o /home/zyb/test.log -O /home/zyb/test.txt http://10.102.55.2/uat8_zjy/batch/down/4100000031_29724130_20240101.txt
                        String logFile = getBankConfig().getValueAsString("logFilePath") + resultFile + ".log";
                        String localFile = getBankConfig().getValueAsString("wageResultFilePath") + seqNumberStart + p_req1998.reqBatchNO + ".txt";
                        //String remoateFile = getBankConfig().getValueAsString("wgetUrl")+resultFile;
                        String remoateFile = resultFile;
                        String transCode = getBankConfig().getValueAsString("fileWagesDownloadTransCode");
                        //WriteBankLogLn("执行的wget命令为："+"wget -d -o "+logFile+" -O "+localFile+" "+remoateFile);
                        WriteBankLogLn("从文件传输平台下载文件开始：" + "日志文件: " + logFile + " 本地文件:" + localFile + " 遠程文件:" + remoateFile);
                        //int wgetResult = WgetUtil.getFile(logFile, localFile, remoateFile, errMsg);
                        int transferResult = WgetUtil.downLoadFile(remoateFile, localFile, transCode, errMsg, this.getConfig());
                        if (transferResult == 0) {
                            WriteBankLogLn("从文件传输平台获取文件成功，保存于：" + localFile);
                            //文件获取成功则删除日志文件
                            try {
                                File file = new File(logFile);
                                if (file != null && file.exists()) {
                                    file.delete();
                                }
                            } catch (Exception e) {
                                //删除日志文件发生异常不影响业务
                                e.printStackTrace();
                                WriteBankLogLn("删除日志文件发生异常，不影响业务，继续进行，异常信息如下：" + e.getMessage());
                            }

                            Map<String, Map<String, String>> result = readFileContext(localFile, false);
                            if (result != null && !result.isEmpty()) {
                                if (p_req1998.totalNum.equals(result.get("header").get("totalNum"))) {
                                    retAts.respCode = "0";
                                    retAts.respInfo = ret_code + "-" + tmpStatusText;
                                    retAts.reqSeqID = p_req1998.reqBatchNO;
                                    retAts.writeBeforeDetail();
                                    for (String key : result.keySet()) {
                                        if ("header".equals(key)) {
                                            continue;
                                        }
                                        RetAtsBatPayRecDetail tmpRetDetail = new RetAtsBatPayRecDetail();
                                        Map<String, String> row = result.get(key);
                                        tmpRetDetail.payAct = p_req1998.ownAct;
                                        tmpRetDetail.recAct = row.get("recAct");
                                        tmpRetDetail.recName = row.get("recName");
                                        tmpRetDetail.payAmount = row.get("amount");
                                        tmpRetDetail.result = row.get("payState");
                                        tmpRetDetail.postScript = row.get("serialNum");
                                        tmpRetDetail.payInfoCode = row.get("payInfo");
                                        retAts.writeRetDetail(tmpRetDetail);
                                    }
                                } else {
                                    throw new Exception("结果文件中的头部信息有误！总笔数:" + result.get("totalNum") + "笔，与MBC中不一致！");
                                }
                            } else {
                                throw new Exception("读取结果文件异常，获取到的内容为空！");
                            }
                        } else {
                            throw new Exception("通过文件传输平台获取文件异常：" + errMsg.toString());
                        }
                    } else {
                        /**
                         * if("0".equals(CurstepFlag) || "1".equals(CurstepFlag) || "2".equals(CurstepFlag)){
                         * 	    isSucess = false;
                         * }else if("3".equals(CurstepFlag) && "0".equals(Dealsts)){
                         * 	    if(!"57005".equals(xydm) && !"00000".equals(xydm)){
                         * 		    isSucess = false;
                         *      }
                         * }else if("4".equals(CurstepFlag) && "0".equals(Dealsts)){
                         * 	    if(!"51010".equals(xydm) && !"00000".equals(xydm)){
                         * 		    isSucess = false;
                         *      }
                         * }else if(("5".equals(CurstepFlag) && "1".equals(Dealsts) && (downFileName != null && downFileName.trim().length() > 0))){
                         * 	    //使用中间业务的返回回盘文件名
                         * 	    fileName = downFileName ;
                         * }else{
                         * 	    log.info("==========>AgentPaySalaryJobService回盘中，整合批次号：[" + batchjnlno + "],平台批次号[" + otherSysJnlNo + "]");
                         * 	    continue;
                         * }
                         */
                        String payResult = ret_code;
                        if ("0".equals(CurstepFlag) || "1".equals(CurstepFlag) || "2".equals(CurstepFlag)) {
                            payResult = PaymentState.FAIL_Batch;
                        } else if ("3".equals(CurstepFlag) && "0".equals(Dealsts)) {
                            if (!"57005".equals(ret_code) && !"00000".equals(ret_code)) {
                                payResult = PaymentState.FAIL_Batch;
                            } else {
                                payResult = PaymentState.PAYING;
                            }
                        } else if ("4".equals(CurstepFlag) && "0".equals(Dealsts)) {
                            if (!"51010".equals(ret_code) && !"00000".equals(ret_code)) {
                                payResult = PaymentState.FAIL_Batch;
                            } else {
                                payResult = PaymentState.PAYING;
                            }
                        } else {
                            payResult = PaymentState.PAYING;
                        }
                        retAts.respCode = "0";
                        retAts.respInfo = tmpStatus + "-" + err_msg + "-" + ret_code + "-" + tmpStatusText + "-" + CurstepFlag + "-" + Dealsts;
                        retAts.transState = payResult;
                        retAts.payInfoCode = retAts.respInfo;
                        retAts.reqSeqID = p_req1998.reqBatchNO;
                        retAts.writeBeforeDetail();
                    }
                } else {
                    retAts.respCode = "-1";
                    retAts.respInfo = tmpSbMsg.toString();
                    /*retAts.writeRespCode("-1");
                    retAts.writeRespInfo(tmpSbMsg.toString());*/
                }
            } else {
                retAts.respCode = "-1";
                retAts.respInfo = tmpStrRet[1];
                /*retAts.writeRespCode("-1");
                retAts.writeRespInfo(tmpStrRet[1]);*/
            }
        } catch (Exception e) {
            retAts.respCode = "-1";
            retAts.respInfo = e.getMessage();
            /*retAts.writeRespCode("-1");
            retAts.writeRespInfo(e.getMessage());*/
            e.printStackTrace();
        }
        if ("-1".equals(retAts.respCode) && StringHelper.isNullOrEmpty(retAts.reqSeqID)) {
            retAts.reqSeqID = p_req1998.reqBatchNO;
        }
        if ("-1".equals(retAts.respCode)) {
            retAts.writeBeforeDetail();
        }
        retAts.writeAfterDetail();
        return retAts;
    }

    /**
     * 普通批量代发
     *
     * @param p_req1988
     * @return
     * @throws Exception
     */
    public RetAtsBatPayRec d_198801_BatPay(ReqBatPayRec p_req1988, String accountMode) throws Exception {
        String seqNumberStart = getBankConfig().getMapValueByKey("Sys_Head", "CONSUMER_ID") + reqHeader.corporation;
        RetAtsBatPayRec retAts = new RetAtsBatPayRec(p_req1988.reqHeader);
        String batchPurpose = "";
        //<editor-fold desc="1.组装文件内容并上传">
        int serialNumber = 0;
        StringBuilder fileContext = new StringBuilder();
        StringBuilder scriptMapping = new StringBuilder();
        while (p_req1988.readRecord()) {
            //卡账号|户名|金额|交易备注|币种|序号|
            String recAct = p_req1988.readedDetail.recAct;
            String recName = p_req1988.readedDetail.recName;
            String payAmount = p_req1988.readedDetail.payAmount;
            //String askNumber = p_req1988.readedDetail.memo;//备注，这里不埋流水号，就放备注
            String askNumber = p_req1988.readedDetail.purpose;
            String payCur = convertCurToBank(p_req1988.readedDetail.payCur);
            String row = recAct + FILESEPARATOR + recName + FILESEPARATOR + payAmount + FILESEPARATOR
                    + askNumber + FILESEPARATOR + payCur + FILESEPARATOR + (++serialNumber) + FILESEPARATOR + "\r\n";
            fileContext.append(row);

            if (StringHelper.isNullOrEmpty(batchPurpose)) {
                //batchPurpose = p_req1988.readedDetail.purpose;
                batchPurpose = p_req1988.readedDetail.memo;
            }

            scriptMapping.append(p_req1988.readedDetail.askNumber).append("\r\n");
        }

        boolean uploadResult = false;

        //顺序号和ats流水号的映射关系保存到文件
        String scriptFileName = Format.Date8Format.format(DateHelper.convertToDateExtra(p_req1988.payDate)) + seqNumberStart + p_req1988.reqBatchNO + "_script.txt";
        if (scriptMapping.length() > 0) {
            String fileContextStr = StringHelper.trimEnd(scriptMapping.toString(), "\r\n");
            uploadResult = fileUpload(fileContextStr, scriptFileName, getBankConfig().getValueAsString("batchFilePath"), "GBK");
            if (!uploadResult) {
                retAts.respCode = "0";
                retAts.respInfo = "保存顺序号和流水号映射关系失败！";
                retAts.reqSeqID = p_req1988.reqBatchNO;
                retAts.transState = PaymentState.FAIL_Batch;
                retAts.payInfoCode = ConnState.FAIL + "-" + retAts.respInfo;
                retAts.writeRetToATS();
                return retAts;
            }
        } else {
            retAts.respCode = "0";
            retAts.respInfo = "顺序号和流水号映射关系内容为空！";
            retAts.reqSeqID = p_req1988.reqBatchNO;
            retAts.transState = PaymentState.FAIL_Batch;
            retAts.payInfoCode = ConnState.FAIL + "-" + retAts.respInfo;
            retAts.writeRetToATS();
            return retAts;
        }

        //文件名：BATCH_TRANS_渠道(SOURCE_TYPE)_批次号.txt
        String fileName = "BATCH_TRANS_" + getBankConfig().getMapValueByKey("Sys_Head", "SOURCE_TYPE") + "_" + seqNumberStart + p_req1988.reqBatchNO + ".txt";
        //文件上传
        if (fileContext.toString().length() > 0) {
            String fileContextStr = StringHelper.trimEnd(fileContext.toString(), "\r\n");
            uploadResult = fileUpload(fileContextStr, fileName, getBankConfig().getValueAsString("batchFilePath"), "GBK");
        } else {
            retAts.respCode = "0";
            retAts.respInfo = "没有获取到批量支付明细信息";
            retAts.reqSeqID = p_req1988.reqBatchNO;
            retAts.transState = PaymentState.FAIL_Batch;
            retAts.payInfoCode = ConnState.FAIL + "-" + retAts.respInfo;
            retAts.writeRetToATS();
            return retAts;
        }
        //</editor-fold>

        //<editor-fold desc="通知银行">
        if (uploadResult) {
            //通用参数赋值
            ZYB02Header bankHeader = new ZYB02Header();
            bankHeader.SEQ_NO = seqNumberStart + reqHeader.reqSeqID;
            bankHeader.TRAN_CODE = getBankConfig().getMapValueByKey("TRANS_CODE", "SAMEBANKBATCHPAY");
            String transTime = p_req1988.reqHeader.transTime;
            bankHeader.TRAN_DATE = Format.Date10Format.format(DateHelper.convertToDateExtra(transTime));
            bankHeader.TRAN_TIMESTAMP = TIME12FORMAT.format(DateHelper.convertToDateExtra(transTime));
            bankHeader.USER_IP = getIpInfoMap(p_req1988.getOriReqXml()).get("userIP");
            bankHeader.SERVER_IP = getIpInfoMap(p_req1988.getOriReqXml()).get("serverIP");
            //发银行报文的XML对象
            XmlTextWriter xmlWriter = new XmlTextWriter();
            xmlWriter.autoFormat = false;
            //写入通用的头部节点
            writeCommon(xmlWriter, bankHeader);

            //<editor-fold desc="通知银行业务字段">
            xmlWriter.writeElementString("BatchNo", seqNumberStart + p_req1988.reqBatchNO);
            xmlWriter.writeElementString("FileName", fileName);
            xmlWriter.writeElementString("PayerAccountNo", p_req1988.ownAct);
            xmlWriter.writeElementString("PayerAccountName", p_req1988.ownActName);
            xmlWriter.writeElementString("PayerCurrency", convertCurToBank(p_req1988.ownCur));
            xmlWriter.writeElementString("TrsPassword", "");
            xmlWriter.writeElementString("TotalAmount", p_req1988.totalAmt);
            xmlWriter.writeElementString("TotalCount", p_req1988.totalNum);
            xmlWriter.writeElementString("ValidPassFlag", "");
            xmlWriter.writeElementString("TallyType", accountMode);
            xmlWriter.writeElementString("Narrative", batchPurpose);//批次的用途
            xmlWriter.writeElementString("OrgCode", p_req1988.payOrganizationCode);
            //</editor-fold>

            xmlWriter.writeEndElement();
            xmlWriter.writeEndDocument();

            String[] retStrArr = sendXmlToBank(xmlWriter.toXmlString());
            //解析银行返回
            if (retStrArr[0].length() == 0) {
                StringBuilder tmpSbMsg = new StringBuilder();
                XmlTextReader tmpBkReader = loadBankRespXmlReader(retStrArr[1], tmpSbMsg);
                if (tmpBkReader != null) {
                    String ret_code = tmpBkReader.getFirstText("/Message/Head/_RejCode");
                    String ret_msg = tmpBkReader.getFirstText("/Message/Head/_RejMsg");
                    String process_state = tmpBkReader.getFirstText("/Message/Head/_ProcessState");
                    retAts.respCode = "0";
                    retAts.reqSeqID = p_req1988.reqBatchNO;
                    retAts.respInfo = ret_msg;
                    retAts.transState = process_state;
                    retAts.payInfoCode = ret_code + "-" + ret_msg;
                } else {
                    retAts.respCode = "-1";
                    retAts.respInfo = tmpSbMsg.toString();
                    /*retAts.writeRespCode("-1");
                    retAts.writeRespInfo(tmpSbMsg.toString());*/
                }
            } else {
                retAts.respCode = "-1";
                retAts.respInfo = retStrArr[1];
                /*retAts.writeRespCode("-1");
                retAts.writeRespInfo(retStrArr[1].toString());*/
            }
        } else {
            retAts.respCode = "0";
            retAts.respInfo = "批量付款文件上传失败";
            retAts.reqSeqID = p_req1988.reqBatchNO;
            retAts.transState = PaymentState.FAIL_Batch;
            retAts.payInfoCode = ConnState.FAIL + "-" + retAts.respInfo;
            retAts.writeRetToATS();
            return retAts;
        }
        //</editor-fold>
        retAts.writeRetToATS();
        return retAts;
    }

    /**
     * 普通批量代发状态查询
     *
     * @param p_req1998
     * @return
     * @throws Exception
     */
    public RetAtsQryBatPayRec d_199801_QryBatPay(ReqQryBatPayRec p_req1998) throws Exception {
        String seqNumberStart = getBankConfig().getMapValueByKey("Sys_Head", "CONSUMER_ID") + reqHeader.corporation;
        //返回ATS的对象
        RetAtsQryBatPayRec retAts = new RetAtsQryBatPayRec(p_req1998.reqHeader);
        try {
            //通用参数赋值
            ZYB02Header bankHeader = new ZYB02Header();
            bankHeader.SEQ_NO = seqNumberStart + reqHeader.transSeqID;
            bankHeader.TRAN_CODE = getBankConfig().getMapValueByKey("TRANS_CODE", "SAMEBANKBATCHPAYQUERY");
            String transTime = p_req1998.reqHeader.transTime;
            bankHeader.TRAN_DATE = Format.Date10Format.format(DateHelper.convertToDateExtra(transTime));
            bankHeader.TRAN_TIMESTAMP = TIME12FORMAT.format(DateHelper.convertToDateExtra(transTime));
            bankHeader.USER_IP = getIpInfoMap(p_req1998.getOriReqXml()).get("userIP");
            bankHeader.SERVER_IP = getIpInfoMap(p_req1998.getOriReqXml()).get("serverIP");
            //发银行报文的XML对象
            XmlTextWriter xmlWriter = new XmlTextWriter();
            xmlWriter.autoFormat = false;
            //写入通用的头部节点
            writeCommon(xmlWriter, bankHeader);

            xmlWriter.writeElementString("BatchNo", seqNumberStart + p_req1998.reqBatchNO);

            xmlWriter.writeEndElement();
            xmlWriter.writeEndDocument();

            String[] tmpStrRet = sendXmlToBank(xmlWriter.toXmlString());
            if (tmpStrRet[0].length() == 0) {
                StringBuilder tmpSbMsg = new StringBuilder();
                XmlTextReader tmpBkReader = loadBankRespXmlReader(tmpStrRet[1], tmpSbMsg);

                if (tmpBkReader != null) {
                    String ret_code = tmpBkReader.getFirstText("/Message/Head/_RejCode");
                    String ret_msg = tmpBkReader.getFirstText("/Message/Head/_RejMsg");
                    String resultFile = tmpBkReader.getFirstText("/Message/Body/FilePath");

                    if (ret_code != null && ret_code.equals(RET_CODE)) {
                        WriteBankLogLn("结果文件路径：" + resultFile);
                        String fileName = "";
                        if (StringHelper.hasAnyChar(resultFile)) {
                            String[] filePath = resultFile.split("/");
                            if (filePath != null && filePath.length > 0) {
                                fileName = filePath[filePath.length - 1];
                            }
                        }
                        if (StringHelper.isNullOrEmpty(fileName)) {
                            retAts.respCode = "-1";
                            retAts.respInfo = ret_code + "-" + ret_msg;
                        } else {
                            WriteBankLogLn("分割路径得到文件名：" + fileName);
                            String logFile = getBankConfig().getValueAsString("logFilePath") + fileName + ".log";
                            String localFile = getBankConfig().getValueAsString("batchResultFilePath") + seqNumberStart + p_req1998.reqBatchNO + ".txt";
                            String remoateFile = getBankConfig().getValueAsString("bankInnerWgetUrl") + fileName;
                            WriteBankLogLn("执行的wget命令为：" + "wget -d -o " + logFile + " -O " + localFile + " " + remoateFile);
                            StringBuilder errMsg = new StringBuilder();
                            int wgetResult = WgetUtil.getFile(logFile, localFile, remoateFile, errMsg);
                            if (wgetResult == 0) {
                                WriteBankLogLn("wget获取文件成功，保存于：" + localFile);
                                //文件获取成功则删除日志文件
                                try {
                                    File file = new File(logFile);
                                    if (file != null && file.exists()) {
                                        file.delete();
                                    }
                                } catch (Exception e) {
                                    //删除日志文件发生异常不影响业务
                                    e.printStackTrace();
                                    WriteBankLogLn("删除wget日志文件发生异常，不影响业务，继续进行，异常信息如下：" + e.getMessage());
                                }

                                Map<String, Map<String, String>> result = readFileContext(localFile, true);
                                if (result != null && !result.isEmpty()) {
                                    retAts.respCode = "0";
                                    retAts.respInfo = ret_code + "-" + ret_msg;
                                    retAts.reqSeqID = p_req1998.reqBatchNO;
                                    //retAts.writeBeforeDetail();
                                    WriteBankLogLn("开始读取顺序号和流水号的对应关系...");
                                    //<editor-fold desc="从文件中获取顺序号对应的流水号">
                                    String scriptFileName = Format.Date8Format.format(DateHelper.convertToDateExtra(p_req1998.bgnDate)) + seqNumberStart + p_req1998.reqBatchNO + "_script.txt";
                                    String filePath = getBankConfig().getValueAsString("batchFilePath") + scriptFileName;
                                    String fileContent = FileHelper.readFileText(filePath, "GBK");
                                    String[] scriptMapping = fileContent.split("\r\n");
                                    if (!(scriptMapping != null && scriptMapping.length == Integer.parseInt(p_req1998.totalNum))) {
                                        throw new Exception("没有读取到顺序号和流水号映射关系！");
                                    }
                                    //</editor-fold>
                                    WriteBankLogLn("顺序号和流水号映射关系内容：" + fileContent);

                                    for (String key : result.keySet()) {
                                        RetAtsBatPayRecDetail tmpRetDetail = new RetAtsBatPayRecDetail();
                                        Map<String, String> row = result.get(key);
                                        tmpRetDetail.payAct = p_req1998.ownAct;
                                        tmpRetDetail.recAct = row.get("recAct");
                                        //tmpRetDetail.recName = row.get("recName");
                                        tmpRetDetail.payAmount = row.get("amount");
                                        tmpRetDetail.result = row.get("payState");
                                        tmpRetDetail.postScript = scriptMapping[Integer.parseInt(row.get("serialNum")) - 1];
                                        tmpRetDetail.payInfoCode = row.get("payInfo");
                                        retAts.writeRetDetail(tmpRetDetail);
                                    }
                                    WriteBankLogLn("循环结束...");
                                } else {
                                    throw new Exception("读取结果文件异常，获取到的内容为空！");
                                }
                            } else {
                                throw new Exception("通过wget获取文件异常：" + errMsg.toString());
                            }
                        }
                    } else {
                        if ("111111".equals(ret_code) || "300726".equals(ret_code)) {
                            retAts.respCode = "-1";
                            retAts.respInfo = ret_code + "-" + ret_msg;
                        } else {
                            retAts.respCode = "0";
                            retAts.respInfo = ret_code + "-" + ret_msg;
                            retAts.reqSeqID = p_req1998.reqBatchNO;
                            retAts.transState = PaymentState.FAIL_Batch;
                            retAts.payInfoCode = ConnState.FAIL + "-" + retAts.respInfo;
                            if (!retAts.hasWrittenRespCode) {
                                retAts.writeBeforeDetail();
                            }
                        }
                        //retAts.respCode = "-1";
                        //retAts.respInfo = ret_code+"-"+ret_msg;
                        /*retAts.writeRespCode("-1");
                        retAts.writeRespInfo(ret_code+"-"+ret_msg);*/
                    }
                } else {
                    retAts.respCode = "-1";
                    retAts.respInfo = tmpSbMsg.toString();
                    /*retAts.writeRespCode("-1");
                    retAts.writeRespInfo(tmpSbMsg.toString());*/
                }
            } else {
                retAts.respCode = "-1";
                retAts.respInfo = tmpStrRet[1];
                /*retAts.writeRespCode("-1");
                retAts.writeRespInfo(tmpStrRet[1]);*/
            }
        } catch (Exception e) {
            retAts.respCode = "-1";
            retAts.respInfo = e.getMessage();
            /*retAts.writeRespCode("-1");
            retAts.writeRespInfo(e.getMessage());*/
            e.printStackTrace();
        }
        if ("-1".equals(retAts.respCode) && StringHelper.isNullOrEmpty(retAts.reqSeqID)) {
            retAts.reqSeqID = p_req1998.reqBatchNO;
        }
        if ("-1".equals(retAts.respCode)) {
            if (!retAts.hasWrittenRespCode) {
                retAts.writeBeforeDetail();
            }
        }
        retAts.writeAfterDetail();
        return retAts;
    }

    /**
     * 跨行批量一笔记账支付提交
     *
     * @param p_req1988
     * @return
     * @throws Exception
     */
    public RetAtsBatPayRec d_198804_BatPay(ReqBatPayRec p_req1988) throws Exception {
        String oriReqXml = p_req1988.getOriReqXml();
        RetAtsBatPayRec retAts = new RetAtsBatPayRec(p_req1988.reqHeader);
        //String seqNumberStart = getBankConfig().getMapValueByKey("Sys_Head","CONSUMER_ID")+reqHeader.corporation;
        String seqNumberStart = reqHeader.corporation;

        //<editor-fold desc="手续费查询">
        //批量查询每一笔跨行交易的手续费Map的key为支付流水号value是个Map它的key是chg_amt即手续费
        StringBuilder feeErrMsg = new StringBuilder();
        Map<String, Map<String, String>> poundAgeMap = getPoundage(oriReqXml, p_req1988.reqHeader, feeErrMsg);
        String totalFee = "";//手续费总金额
        if (poundAgeMap == null || poundAgeMap.isEmpty() || feeErrMsg.length() > 0) {
            retAts.respCode = "0";
            retAts.respInfo = feeErrMsg.toString();
            retAts.reqSeqID = p_req1988.reqBatchNO;
            retAts.transState = PaymentState.FAIL_Batch;
            retAts.payInfoCode = ConnState.FAIL + "-" + retAts.respInfo;
            retAts.writeRetToATS();
            return retAts;
        } else {
            BigDecimal totalFeeTemp = new BigDecimal(0);
            for (String key : poundAgeMap.keySet()) {
                String chg_amt = poundAgeMap.get(key).get("chg_amt");
                totalFeeTemp = totalFeeTemp.add(new BigDecimal(chg_amt));
            }
            totalFee = new DecimalFormat2("0.00").format(totalFeeTemp);
        }
        //</editor-fold>

        String atsBatchNo = seqNumberStart + p_req1988.reqBatchNO.substring(2);
        boolean uploadResult = false;
        String batchPurpose = "";
        //<editor-fold desc="生成跨行一笔记账批量付款明细文件">
        StringBuilder detailFileContext = new StringBuilder();
        int serialNumber = 0;
        StringBuilder scriptMapping = new StringBuilder();//顺序号和ats流水号的映射关系保存到文件
        while (p_req1988.readRecord()) {
            //批次号|序号|收款行行号|收款人账号|收款人名称|业务优先级|金额|手续费金额|手续费收费类型|手续费收费方式|附言:埋入流水号|
            serialNumber++;
            String askNumber = p_req1988.readedDetail.askNumber;
            StringBuilder row = new StringBuilder();
            row.append(getBankConfig().getMapValueByKey("Sys_Head", "CONSUMER_ID") + atsBatchNo).append(FILESEPARATOR);//批次号
            row.append(serialNumber).append(FILESEPARATOR);//序号
            row.append(p_req1988.readedDetail.cnapsCode).append(FILESEPARATOR);//收款行行号
            row.append(p_req1988.readedDetail.recAct).append(FILESEPARATOR);//收款人账号
            row.append(p_req1988.readedDetail.recName).append(FILESEPARATOR);//收款人名称
            row.append(p_req1988.readedDetail.paySpd.equals("1") ? "HIGH" : "NORM").append(FILESEPARATOR);//业务优先级:是否加急
            row.append(p_req1988.readedDetail.payAmount).append(FILESEPARATOR);//金额
            row.append(poundAgeMap.get(askNumber).get("chg_amt")).append(FILESEPARATOR);//手续费金额
            row.append("W06").append(FILESEPARATOR);//手续费收费类型
            row.append("T").append(FILESEPARATOR);//手续费收费方式
            //String purpose = p_req1988.readedDetail.purpose;
            String purpose = p_req1988.readedDetail.memo;
            //跨行批量一笔记账附言不能为空，所以为空时给默认值
            if (StringHelper.isNullOrEmpty(purpose)) {
                purpose = "转账";
            }
            row.append(purpose);//附言
            row.append("\r\n");
            detailFileContext.append(row);

            if (StringHelper.isNullOrEmpty(batchPurpose)) {
                batchPurpose = purpose;
            }

            scriptMapping.append(p_req1988.readedDetail.askNumber).append("\r\n");
        }
        //跨行批量上传文件传输代码
        String transCode = getBankConfig().getValueAsString("fileBatchAcrossBankUploadTransCode");
        //跨行批量上传文件路径
        String remoteFilePath = getBankConfig().getValueAsString("fileBatchAcrossBankPath");
        //文件传输平台返回的汇总文件路径
        String responseRemoteTotalFilePath = null;
        //文件传输平台返回的明细文件路径
        String responseRemoteDetailFilePath = null;
        //顺序号和ats流水号的映射关系保存到文件
        String scriptFileName = Format.Date8Format.format(DateHelper.convertToDateExtra(p_req1988.payDate)) + atsBatchNo + "_script.txt";
        if (scriptMapping.length() > 0) {
            String fileContextStr = StringHelper.trimEnd(scriptMapping.toString(), "\r\n");
            uploadResult = fileUpload(fileContextStr, scriptFileName, getBankConfig().getValueAsString("arsFilePath"), "UTF-8");
            if (!uploadResult) {
                retAts.respCode = "0";
                retAts.respInfo = "保存顺序号和流水号映射关系失败！";
                retAts.reqSeqID = p_req1988.reqBatchNO;
                retAts.transState = PaymentState.FAIL_Batch;
                retAts.payInfoCode = ConnState.FAIL + "-" + retAts.respInfo;
                retAts.writeRetToATS();
                return retAts;
            }
        } else {
            retAts.respCode = "0";
            retAts.respInfo = "顺序号和流水号映射关系内容为空！";
            retAts.reqSeqID = p_req1988.reqBatchNO;
            retAts.transState = PaymentState.FAIL_Batch;
            retAts.payInfoCode = ConnState.FAIL + "-" + retAts.respInfo;
            retAts.writeRetToATS();
            return retAts;
        }

        String detailFileName = "CROSSBANKBATCH_TRANS_MU_ACCT_" + Format.Date8Format.format(DateHelper.convertToDateExtra(p_req1988.payDate)) + "_" + atsBatchNo + ".txt";
        if (detailFileContext.toString().length() > 0) {
            String fileContextStr = StringHelper.trimEnd(detailFileContext.toString(), "\r\n");
            //uploadResult = fileUpload(fileContextStr,detailFileName,getBankConfig().getValueAsString("arsFilePath"),"UTF-8");
            //先上传到本地共享文件夹
            uploadResult = fileUpload(fileContextStr, detailFileName, getBankConfig().getValueAsString("arsFilePath"), "UTF-8");
            if (!uploadResult) {
                retAts.respCode = "0";
                retAts.respInfo = "共享目录生成跨行一笔记账批量付款明细文件失败！";
                retAts.reqSeqID = p_req1988.reqBatchNO;
                retAts.transState = PaymentState.FAIL_Batch;
                retAts.payInfoCode = ConnState.FAIL + "-" + retAts.respInfo;
                retAts.writeRetToATS();
                return retAts;
            }
            responseRemoteDetailFilePath = WgetUtil.uploadFile(getBankConfig().getValueAsString("arsFilePath")
                    + detailFileName, remoteFilePath + File.separator + detailFileName, transCode, this.getConfig());
            responseRemoteDetailFilePath = responseRemoteDetailFilePath.replace(detailFileName, "");
            if (responseRemoteDetailFilePath == null) {
                retAts.respCode = "0";
                retAts.respInfo = "上传跨行一笔记账批量付款明细文件失败！";
                retAts.reqSeqID = p_req1988.reqBatchNO;
                retAts.transState = PaymentState.FAIL_Batch;
                retAts.payInfoCode = ConnState.FAIL + "-" + retAts.respInfo;
                retAts.writeRetToATS();
                return retAts;
            }
        } else {
            retAts.respCode = "0";
            retAts.respInfo = "没有获取到批量支付明细信息";
            retAts.reqSeqID = p_req1988.reqBatchNO;
            retAts.transState = PaymentState.FAIL_Batch;
            retAts.payInfoCode = ConnState.FAIL + "-" + retAts.respInfo;
            retAts.writeRetToATS();
            return retAts;
        }
        //</editor-fold>

        //<editor-fold desc="生成跨行一笔记账批量付款汇总文件">
        uploadResult = false;
        StringBuilder totalFileContext = new StringBuilder();
        totalFileContext.append(getBankConfig().getMapValueByKey("Sys_Head", "CONSUMER_ID") + atsBatchNo).append(FILESEPARATOR);//批次号
        totalFileContext.append(p_req1988.totalAmt).append(FILESEPARATOR);//总金额
        totalFileContext.append(p_req1988.totalNum).append(FILESEPARATOR);//总笔数
        totalFileContext.append(totalFee).append(FILESEPARATOR);//手续费总金额
        totalFileContext.append("W06").append(FILESEPARATOR);//手续费收费类型
        totalFileContext.append("T").append(FILESEPARATOR);//手续费收取方式
        totalFileContext.append(p_req1988.payBankLocationCode).append(FILESEPARATOR);//付方开户银行代码
        totalFileContext.append(p_req1988.ownAct).append(FILESEPARATOR);//付款人账号
        totalFileContext.append(p_req1988.ownActName);//付款人名称

        String totalFileName = "CROSSBANKBATCH_TRANS_MU_OK_" + Format.Date8Format.format(DateHelper.convertToDateExtra(p_req1988.payDate)) + "_" + atsBatchNo + ".ok";
        if (totalFileContext.toString().length() > 0) {
            String fileContextStr = StringHelper.trimEnd(totalFileContext.toString(), "\r\n");
            //uploadResult = fileUpload(fileContextStr,totalFileName,getBankConfig().getValueAsString("arsFilePath"),"UTF-8");
            //首先在共享文件夹下面生成一份
            uploadResult = fileUpload(fileContextStr, totalFileName, getBankConfig().getValueAsString("arsFilePath"), "UTF-8");
            if (!uploadResult) {
                retAts.respCode = "0";
                retAts.respInfo = "共享目录生成跨行一笔记账批量付款汇总文件失败！";
                retAts.reqSeqID = p_req1988.reqBatchNO;
                retAts.transState = PaymentState.FAIL_Batch;
                retAts.payInfoCode = ConnState.FAIL + "-" + retAts.respInfo;
                retAts.writeRetToATS();
                return retAts;
            }
            responseRemoteTotalFilePath = WgetUtil.uploadFile(getBankConfig().getValueAsString("arsFilePath")
                    + totalFileName, remoteFilePath + File.separator + totalFileName, transCode, this.getConfig());
            responseRemoteTotalFilePath = responseRemoteTotalFilePath.replace(totalFileName, "");
            if (responseRemoteTotalFilePath == null) {
                retAts.respCode = "0";
                retAts.respInfo = "上传跨行一笔记账批量付款汇总文件失败！";
                retAts.reqSeqID = p_req1988.reqBatchNO;
                retAts.transState = PaymentState.FAIL_Batch;
                retAts.payInfoCode = ConnState.FAIL + "-" + retAts.respInfo;
                retAts.writeRetToATS();
                return retAts;
            }
        } else {
            retAts.respCode = "0";
            retAts.respInfo = "没有获取到批量支付汇总信息";
            retAts.reqSeqID = p_req1988.reqBatchNO;
            retAts.transState = PaymentState.FAIL_Batch;
            retAts.payInfoCode = ConnState.FAIL + "-" + retAts.respInfo;
            retAts.writeRetToATS();
            return retAts;
        }
        //</editor-fold>

        //<editor-fold desc="发送报文通知银行">
        if (uploadResult) {
            //通用参数赋值
            ZYB02Header bankHeader = new ZYB02Header();
            bankHeader.SEQ_NO = getBankConfig().getMapValueByKey("Sys_Head", "CONSUMER_ID") + seqNumberStart + reqHeader.transSeqID;
            bankHeader.TRAN_CODE = getBankConfig().getMapValueByKey("TRANS_CODE", "ACROSSBANKBATCHPAY");
            String transTime = p_req1988.reqHeader.transTime;
            bankHeader.TRAN_DATE = Format.Date10Format.format(DateHelper.convertToDateExtra(transTime));
            bankHeader.TRAN_TIMESTAMP = TIME12FORMAT.format(DateHelper.convertToDateExtra(transTime));
            bankHeader.USER_IP = getIpInfoMap(p_req1988.getOriReqXml()).get("userIP");
            bankHeader.SERVER_IP = getIpInfoMap(p_req1988.getOriReqXml()).get("serverIP");
            //发银行报文的XML对象
            XmlTextWriter xmlWriter = new XmlTextWriter();
            xmlWriter.autoFormat = false;
            String serviceCode = "SVR_INQUIRY";
            //写入通用的头部节点
            writeCommonHeaderAccrossBank(xmlWriter, bankHeader, serviceCode);

            //<editor-fold desc="通知银行业务字段">
            //     xmlWriter.writeElementString("BatchNo", getBankConfig().getMapValueByKey("Sys_Head", "CONSUMER_ID") + atsBatchNo);//批次号
            //     xmlWriter.writeElementString("OkFileName", totalFileName);//汇总文件名称
            //     File totalFile = new File(getBankConfig().getValueAsString("arsFilePath") + totalFileName);
            //     xmlWriter.writeElementString("OkFileLength", StringHelper.valueOf(totalFile.length()));//汇总文件大小
            //     xmlWriter.writeElementString("OkFilePath", remoteFilePath);//新增汇总文件路径
            //     xmlWriter.writeElementString("AcctFileName", detailFileName);//明细文件名称
            //     File detailFile = new File(getBankConfig().getValueAsString("arsFilePath") + detailFileName);
            //     xmlWriter.writeElementString("AcctFileLength", StringHelper.valueOf(detailFile.length()));//明细文件大小
            //     xmlWriter.writeElementString("AcctFilePath", remoteFilePath);//新增明细文件路径
            //     xmlWriter.writeElementString("Remark", batchPurpose);//批次的用途
            //     xmlWriter.writeElementString("PayerAccountNo", p_req1988.ownAct);//付款账号
            //     xmlWriter.writeElementString("PayerAcName", p_req1988.ownActName);//付款户名
            //     xmlWriter.writeElementString("OrgCode", p_req1988.payOrganizationCode);//付款人组织机构代码证
            //</editor-fold>
            xmlWriter.writeElementString("BATCH_NO", getBankConfig().getMapValueByKey("Sys_Head", "CONSUMER_ID") + atsBatchNo);//批次号
            xmlWriter.writeElementString("OK_FILE_NAME", totalFileName);//汇总文件名称
            File totalFile = new File(getBankConfig().getValueAsString("arsFilePath") + totalFileName);
            xmlWriter.writeElementString("OK_FILE_LENGTH", StringHelper.valueOf(totalFile.length()));//汇总文件大小
            xmlWriter.writeElementString("OK_FILE_PATH", responseRemoteTotalFilePath);//新增汇总文件路径
            xmlWriter.writeElementString("ACCT_FILE_NAME", detailFileName);//明细文件名称
            File detailFile = new File(getBankConfig().getValueAsString("arsFilePath") + detailFileName);
            xmlWriter.writeElementString("ACCT_FILE_LENGTH", StringHelper.valueOf(detailFile.length()));//明细文件大小
            xmlWriter.writeElementString("ACCT_FILE_PATH", responseRemoteDetailFilePath);//新增明细文件路径
            xmlWriter.writeElementString("REMARK", batchPurpose);//批次的用途
            xmlWriter.writeEndElement();
            xmlWriter.writeEndDocument();

            String[] retStrArr = sendToBank(xmlWriter.toXmlString());
            //解析银行返回
            if (retStrArr[0].length() == 0) {
                StringBuilder tmpSbMsg = new StringBuilder();
                XmlTextReader tmpBkReader = loadBankRespXmlReader(retStrArr[1], tmpSbMsg);
                if (tmpBkReader != null) {
                    StringBuilder errMsg = new StringBuilder();
                    String ret_code = tmpBkReader.getFirstText("/Reply_Msg/Sys_Head/Ret_ARRAY/Row/RET_CODE");
                    String ret_msg = tmpBkReader.getFirstText("/Reply_Msg/Sys_Head/Ret_ARRAY/Row/RET_MSG");
                    String process_state = tmpBkReader.getFirstText("/Reply_Msg/Sys_Head/RET_STATUS");
                    retAts.respCode = "0";
                    retAts.reqSeqID = p_req1988.reqBatchNO;
                    retAts.respInfo = ret_msg;
                    retAts.transState = process_state;
                    retAts.payInfoCode = ret_code + "-" + ret_msg;
                } else {
                    retAts.respCode = "-1";
                    retAts.respInfo = tmpSbMsg.toString();
                    /*retAts.writeRespCode("-1");
                    retAts.writeRespInfo(tmpSbMsg.toString());*/
                }
            } else {
                retAts.respCode = "-1";
                retAts.respInfo = retStrArr[1];
                /*retAts.writeRespCode("-1");
                retAts.writeRespInfo(retStrArr[1].toString());*/
            }
        } else {
            retAts.respCode = "0";
            retAts.respInfo = "生成文件失败！";
            retAts.reqSeqID = p_req1988.reqBatchNO;
            retAts.transState = PaymentState.FAIL_Batch;
            retAts.payInfoCode = ConnState.FAIL + "-" + retAts.respInfo;
            retAts.writeRetToATS();
            return retAts;
        }
        //</editor-fold>
        retAts.writeRetToATS();
        return retAts;
    }

    /**
     * 跨行一笔记账批量付款状态查询
     *
     * @param p_req1998
     * @return
     * @throws Exception
     */
    public RetAtsQryBatPayRec d_199804_QryBatPay(ReqQryBatPayRec p_req1998) throws Exception {
        //String seqNumberStart = getBankConfig().getMapValueByKey("Sys_Head","CONSUMER_ID")+reqHeader.corporation;
        String seqNumberStart = reqHeader.corporation;
        String atsBatchNo = seqNumberStart + p_req1998.reqBatchNO.substring(2);

        //<editor-fold desc="从文件中获取顺序号对应的流水号">
        String scriptFileName = Format.Date8Format.format(DateHelper.convertToDateExtra(p_req1998.bgnDate)) + atsBatchNo + "_script.txt";
        String filePath = getBankConfig().getValueAsString("arsFilePath") + scriptFileName;
        String fileContent = FileHelper.readFileText(filePath, "UTF-8");
        String[] scriptMapping = fileContent.split("\r\n");
        if (!(scriptMapping != null && scriptMapping.length == Integer.parseInt(p_req1998.totalNum))) {
            throw new Exception("没有读取到顺序号和流水号映射关系！");
        }
        //</editor-fold>

        //返回ATS的对象
        RetAtsQryBatPayRec retAts = new RetAtsQryBatPayRec(p_req1998.reqHeader);
        try {
            /*//通用参数赋值
            ZYB02Header bankHeader = new ZYB02Header();
            bankHeader.SEQ_NO = getBankConfig().getMapValueByKey("Sys_Head","CONSUMER_ID")+seqNumberStart+reqHeader.transSeqID;
            bankHeader.TRAN_CODE = getBankConfig().getMapValueByKey("TRANS_CODE", "ACROSSBANKBATCHPAYQUERY");
            String transTime = p_req1998.reqHeader.transTime;
            bankHeader.TRAN_DATE = Format.Date8Format.format(DateHelper.convertToDateExtra(transTime));
            bankHeader.TRAN_TIMESTAMP = Format.Time9Format.format(DateHelper.convertToDateExtra(transTime));
            //发银行报文的XML对象
            XmlTextWriter xmlWriter = new XmlTextWriter();
            xmlWriter.autoFormat = false;
            //写入通用的头部节点
            writeCommonHeader(xmlWriter, bankHeader);*/

            //通用参数赋值
            ZYB02Header bankHeader = new ZYB02Header();
            bankHeader.SEQ_NO = getBankConfig().getMapValueByKey("Sys_Head", "CONSUMER_ID") + seqNumberStart + reqHeader.transSeqID;
            //bankHeader.TRAN_CODE = getBankConfig().getMapValueByKey("TRANS_CODE", "ACROSSBANKBATCHPAYQUERY");
            String transTime = p_req1998.reqHeader.transTime;
            bankHeader.TRAN_DATE = Format.Date10Format.format(DateHelper.convertToDateExtra(transTime));
            bankHeader.TRAN_TIMESTAMP = TIME12FORMAT.format(DateHelper.convertToDateExtra(transTime));
            bankHeader.USER_IP = getIpInfoMap(p_req1998.getOriReqXml()).get("userIP");
            bankHeader.SERVER_IP = getIpInfoMap(p_req1998.getOriReqXml()).get("serverIP");

            //todo 是否发起单笔查询标记
            //todo 首先去做文件同步,如果文件同步都过去了，不需要做单笔同步了
            bankHeader.TRAN_CODE = getBankConfig().getMapValueByKey("TRANS_CODE", "ACROSSBANKBATCHPAYQUERYBYFILE");
            XmlTextWriter xmlWriterFile = new XmlTextWriter();
            xmlWriterFile.autoFormat = false;
            String serviceCode = "SVR_PTS2_INQUIRY";
            //写入通用的头部节点
            writeCommonHeaderAccrossBank(xmlWriterFile, bankHeader, serviceCode);
            xmlWriterFile.writeElementString("BATCH_NO", getBankConfig().getMapValueByKey("Sys_Head", "CONSUMER_ID") + atsBatchNo);
            xmlWriterFile.writeEndElement();
            xmlWriterFile.writeEndDocument();

            //发送给银行，拿到文件路径以及文件名称
            String[] tmpStrRetFile = sendToBank(xmlWriterFile.toXmlString());

            List<String> sourceReferenceList = new ArrayList<String>();
            //解析银行返回的报文
            if (tmpStrRetFile[0].length() == 0) {
                StringBuilder tmpSbMsg = new StringBuilder();
                XmlTextReader tmpBkReader = loadBankRespXmlReader(tmpStrRetFile[1], tmpSbMsg);
                if (tmpBkReader != null) {
                    String ret_code = tmpBkReader.getFirstText("/Reply_Msg/Sys_Head/RET_ARRAY/Row/RET_CODE");
                    String ret_msg = tmpBkReader.getFirstText("/Reply_Msg/Sys_Head/RET_ARRAY/Row/RET_MSG");
                    if (ret_code != null && ret_code.equals(RET_CODE)) {
                        boolean flag = true;
                        String batch_no = tmpBkReader.getFirstText("/Reply_Msg/Body/BATCH_NO");  //批次号
                        String batch_status = tmpBkReader.getFirstText("/Reply_Msg/Body/BATCH_STATUS");//批处理状态
                        String batch_desc = tmpBkReader.getFirstText("/Reply_Msg/Body/BATCH_DESC");//批处理状态描述
                        String fileName = tmpBkReader.getFirstText("/Reply_Msg/Body/FILE_NAME");//文件名
                        String responseFilePath = tmpBkReader.getFirstText("/Reply_Msg/Body/FILE_PATH");//文件路劲
                        String transCode = getBankConfig().getValueAsString("fileBatchAcrossBankDownloadTransCode");
                        StringBuilder errMsg = new StringBuilder();
                        String remoateFile = responseFilePath + fileName + ".txt";
                        String localFile = getBankConfig().getValueAsString("arsResultFilePath") + fileName + ".txt";
                        //汇总文件和明细文件比对检查通过
                        if ("7".equals(batch_status) || "8".equals(batch_status)) {
                            //文件名和文件路径不能为空
                            int transferResult = WgetUtil.downLoadFile(remoateFile, localFile, transCode, errMsg, this.getConfig());
                            if (transferResult == 0) {
                                WriteBankLogLn("从文件传输平台获取文件成功，保存于：" + localFile);
                                //解析文件
                                List<Map<String, Object>> fileList = this.readFile(localFile);
                                //单独拿到源流水号集合
                                for (Map map : fileList) {
                                    String sourceReference = (String) map.get("sourceReference");//源流水号
                                    sourceReferenceList.add(sourceReference);
                                }
                                retAts.respCode = "0";
                                retAts.respInfo = ret_code+"-"+ret_msg;
                                retAts.reqSeqID = p_req1998.reqBatchNO;
                                for (Map map : fileList) {
                                    flag = false;
                                    String list_status = (String) map.get("list_status");
                                    String tran_status = (String) map.get("tran_status");
                                    String status = (String) map.get("status");
                                    String list_desc = (String) map.get("list_desc");
                                    String tran_desc = (String) map.get("tran_desc");
                                    String order_no = (String) map.get("orderNo");//批次内顺序号
                                    String postScript = scriptMapping[Integer.parseInt(order_no) - 1];//ats流水号
                                    String payResult = status;
                                    RetAtsBatPayRecDetail tmpRetDetail = new RetAtsBatPayRecDetail();
                                    if ("1".equals(list_status)) {
                                        if ("02".equals(tran_status)) {
                                            if ("15".equals(status) || "16".equals(status) || "OK".equals(status)) {
                                                payResult = PaymentState.SUCCESS;
                                                tmpRetDetail.postScript = postScript;
                                                tmpRetDetail.result = payResult;
                                                tmpRetDetail.payInfoCode = status + "-" + list_status + "-" + list_desc + "-" + tran_status + "-" + tran_desc;
                                                retAts.writeRetDetail(tmpRetDetail);
                                                flag = true;
                                            } else {
                                                break;
                                            }
                                        } else {
                                            break;
                                        }
                                    } else {
                                        break;
                                    }
                                }
                            }
                        }else if("2".equals(batch_status)){
                            retAts.respCode = "0";
                            retAts.respInfo = batch_status + "-" + batch_desc;
                            retAts.transState = PaymentState.FAIL_Batch;
                            retAts.payInfoCode = batch_status + "-" + batch_desc;
                            retAts.reqSeqID = p_req1998.reqBatchNO;
                            retAts.writeBeforeDetail();
                        }
                        if (flag) {
                            retAts.writeAfterDetail();
                            return retAts;
                        }

                    }
                }

            }


            //单笔同步，之前的逻辑
            //发银行报文的XML对象
            bankHeader.TRAN_CODE = getBankConfig().getMapValueByKey("TRANS_CODE", "ACROSSBANKBATCHPAYQUERY");
            XmlTextWriter xmlWriter = new XmlTextWriter();
            xmlWriter.autoFormat = false;
            serviceCode = "SVR_PTS2_INQUIRY";
            //写入通用的头部节点
            writeCommonHeaderAccrossBank(xmlWriter, bankHeader, serviceCode);

            xmlWriter.writeElementString("BATCH_NO", getBankConfig().getMapValueByKey("Sys_Head", "CONSUMER_ID") + atsBatchNo);
            xmlWriter.writeStartElement("TRAN_ARRAY");
//            for (int i = 1; i <= Integer.parseInt(p_req1998.totalNum); i++) {
//                XElement row = new XElement("Row", "");
//                row.addChild(new XElement("SOURCE_REFERENCE", seq_no));
//                xmlWriter.writeXElement(row);
//            }
            for(String sourceReference:sourceReferenceList){
                XElement row = new XElement("Row", "");
                row.addChild(new XElement("SOURCE_REFERENCE", sourceReference));
                xmlWriter.writeXElement(row);
            }

            xmlWriter.writeEndElement();
            xmlWriter.writeEndDocument();

            String[] tmpStrRet = sendToBank(xmlWriter.toXmlString());
            if (tmpStrRet[0].length() == 0) {
                StringBuilder tmpSbMsg = new StringBuilder();
                XmlTextReader tmpBkReader = loadBankRespXmlReader(tmpStrRet[1], tmpSbMsg);

                if (tmpBkReader != null) {
                    String ret_code = tmpBkReader.getFirstText("/Reply_Msg/Sys_Head/RET_ARRAY/Row/RET_CODE");
                    String ret_msg = tmpBkReader.getFirstText("/Reply_Msg/Sys_Head/RET_ARRAY/Row/RET_MSG");
                    //String process_state = tmpBkReader.getFirstText("/Message/Head/_ProcessState");
                    if (ret_code != null && ret_code.equals(RET_CODE)) {
                        String batch_no = tmpBkReader.getFirstText("/Reply_Msg/Body/BATCH_NO");
                        String batch_status = tmpBkReader.getFirstText("/Reply_Msg/Body/BATCH_STATUS");
                        String batch_desc = tmpBkReader.getFirstText("/Reply_Msg/Body/BATCH_DESC");
                        if ("1".equals(batch_status)) {//汇总文件和明细文件比对检查通过
                            retAts.respCode = "0";
                            retAts.respInfo = ret_code + "-" + ret_msg;
                            retAts.reqSeqID = p_req1998.reqBatchNO;
                            while (tmpBkReader.read("/Reply_Msg/Body/List/Map")) {
                                String payer_acct = tmpBkReader.readedXElement.getSingleText("PayerAcct");//付款人账号
                                String payee_acct = tmpBkReader.readedXElement.getSingleText("PayeeAcct");//收款人账号
                                String payee_name = tmpBkReader.readedXElement.getSingleText("PayeeName");//收款人名称
                                String tran_amt = tmpBkReader.readedXElement.getSingleText("TranAmt");//交易金额
                                String status = tmpBkReader.readedXElement.getSingleText("Status");//交易状态
                                String order_no = tmpBkReader.readedXElement.getSingleText("OrderNo");//批次内顺序号
                                String postScript = scriptMapping[Integer.parseInt(order_no) - 1];//ats流水号
                                String list_status = tmpBkReader.readedXElement.getSingleText("ListStatus");//明细处理状态
                                String list_desc = tmpBkReader.readedXElement.getSingleText("ListDesc");//明细处理状态描述
                                String tran_status = tmpBkReader.readedXElement.getSingleText("TranStatus");//记账状态
                                String tran_desc = tmpBkReader.readedXElement.getSingleText("TranDesc");//记账状态描述
                                /** 20181206 刘延涛给的处理办法
                                 * 批次外 ：batchStatus  0-明细文件还未解析因为支付解析文件是异步处理  2 --该批次已作废 1 汇总文件和明细文件比对检查通过
                                 * batchStatus  1
                                 * list
                                 * 	listStatus  0：明细解析成功 UC
                                 * 	listStatus -1 解析文件错误   2 明细已作废  3 支付系统发送人行失败需要冲正 全部置为FL失败
                                 * 	listStatus 1：说明这笔明细已经录入成功
                                 * 		tranStatus  02
                                 * 			status  15 16 OK代表转账成功  55 失败 else ＵＣ
                                 * 		tranStatus　０３
                                 * 			status 56 58  失败
                                 * 		tranStatus 05
                                 * 			status  20 45 58 失败
                                 * 		else UC
                                 */
                                String payResult = status;
                                if ("1".equals(list_status)) {
                                    if ("02".equals(tran_status)) {
                                        if ("15".equals(status) || "16".equals(status) || "OK".equals(status)) {
                                            payResult = PaymentState.SUCCESS;
                                        } else if ("55".equals(status)) {
                                            payResult = PaymentState.FAIL_Payment;
                                        } else {
                                            payResult = PaymentState.PAYING;
                                        }
                                    } else if ("03".equals(tran_status)) {
                                        if ("56".equals(status) || "58".equals(status)) {
                                            payResult = PaymentState.FAIL_Payment;
                                        } else {
                                            payResult = PaymentState.PAYING;
                                        }
                                    } else if ("05".equals(tran_status)) {
                                        if ("20".equals(status) || "45".equals(status) || "58".equals(status)) {
                                            payResult = PaymentState.FAIL_Payment;
                                        } else {
                                            payResult = PaymentState.PAYING;
                                        }
                                    } else {
                                        payResult = PaymentState.PAYING;
                                    }
                                } else if ("-1".equals(list_status) || "2".equals(list_status) || "3".equals(list_status)) {
                                    payResult = PaymentState.FAIL_Payment;
                                } else if ("0".equals(list_status)) {
                                    payResult = PaymentState.PAYING;
                                } else {
                                    payResult = PaymentState.PAYING;
                                }

                                RetAtsBatPayRecDetail tmpRetDetail = new RetAtsBatPayRecDetail();
                                tmpRetDetail.payAct = payer_acct;
                                tmpRetDetail.recAct = payee_acct;
                                tmpRetDetail.recName = payee_name;
                                tmpRetDetail.payAmount = tran_amt;
                                tmpRetDetail.result = payResult;
                                tmpRetDetail.postScript = postScript;
                                tmpRetDetail.payInfoCode = status + "-" + list_status + "-" + list_desc + "-" + tran_status + "-" + tran_desc;
                                retAts.writeRetDetail(tmpRetDetail);
                            }
                        } else if ("0".equals(batch_status)) {//明细文件还未解析
                            retAts.respCode = "-1";
                            retAts.respInfo = batch_status + "-" + batch_desc;
                        } else if ("2".equals(batch_status)) {//该批次已作废
                            retAts.respCode = "0";
                            retAts.respInfo = batch_status + "-" + batch_desc;
                            retAts.transState = PaymentState.FAIL_Batch;
                            retAts.payInfoCode = batch_status + "-" + batch_desc;
                            retAts.reqSeqID = p_req1998.reqBatchNO;
                            retAts.writeBeforeDetail();
                        }
                    } else {
                        retAts.respCode = "-1";
                        retAts.respInfo = ret_code + "-" + ret_msg;
                        /*retAts.writeRespCode("-1");
                        retAts.writeRespInfo(ret_code + "-" + ret_msg);*/
                    }
                } else {
                    retAts.respCode = "-1";
                    retAts.respInfo = tmpSbMsg.toString();
                    /*retAts.writeRespCode("-1");
                    retAts.writeRespInfo(tmpSbMsg.toString());*/
                }
            } else {
                retAts.respCode = "-1";
                retAts.respInfo = tmpStrRet[1];
                /*retAts.writeRespCode("-1");
                retAts.writeRespInfo(tmpStrRet[1]);*/
            }
        } catch (Exception e) {
            retAts.respCode = "-1";
            retAts.respInfo = e.getMessage();
            /*retAts.writeRespCode("-1");
            retAts.writeRespInfo(e.getMessage());*/
            e.printStackTrace();
        }
        if ("-1".equals(retAts.respCode) && StringHelper.isNullOrEmpty(retAts.reqSeqID)) {
            retAts.reqSeqID = p_req1998.reqBatchNO;
        }
        if ("-1".equals(retAts.respCode)) {
            retAts.writeBeforeDetail();
        }
        retAts.writeAfterDetail();
        return retAts;
    }

    /**
     * 文件上传
     *
     * @param fileContext
     * @param fileName
     * @return
     * @throws Exception
     */
    private boolean fileUpload(String fileContext, String fileName, String filePath, String charset) throws Exception {
        String fileFullPath = filePath + fileName;
        WriteBankLogLn("批次文件保存位置：" + fileFullPath);
        WriteBankLogLn2("批次文件内容：\r\n" + fileContext);
        FileHelper.writeFile(fileFullPath, fileContext, charset);
        WriteBankLogLn("批次文件保存成功！");
        return true;
    }


    public List<Map<String, Object>> readFile(String filePath) throws IOException {
        String fileContext = new String(FileHelper.readFileBytes(filePath));
        //WriteBankLogLn("读取的文件内容为：" + fileContext);
        String[] rows = fileContext.split("\n");
        List<Map<String, Object>> fileList = new ArrayList<Map<String, Object>>();
        for (int i = 0; i < rows.length; i++) {
            Map<String, Object> map = new HashMap<String, Object>();
            String row = rows[i];
            String[] fields = row.split("\\|");
            map.put("serialNo", fields[0]);  //批次号
            map.put("orderNo",fields[1]);
            map.put("sourceReference",fields[7]);  //流水号
            //map.put("D",fields[3]);
            //map.put("E",fields[4]);
            //map.put("F",fields[5]);
            //map.put("G",fields[6]);
            //map.put("H",fields[7]);
            //map.put("I",fields[8]);
            map.put("tran_status", fields[9]);//记账状态
            map.put("status", fields[10]); //交易状态
            map.put("list_status", fields[11]);  //明细处理状态
            map.put("list_desc", fields[12]);//明细描述
            map.put("tran_desc", fields[13]);//交易描述
            fileList.add(map);
        }
        return fileList;
    }

    private Map<String, Map<String, String>> readFileContext(String filePath, Boolean isBankInner) throws IOException {
        Map<String, Map<String, String>> result = new HashMap<String, Map<String, String>>();
        String fileContext = new String(FileHelper.readFileBytes(filePath), "GBK");
        WriteBankLogLn("读取的文件内容为：" + fileContext);
        String[] rows = fileContext.split("\n");
        if (isBankInner) {
            for (int i = 0; i < rows.length; i++) {
                String row = rows[i];
                String[] fields = row.split("\\|", 100);
                Map<String, String> fieldsMap = new HashMap<String, String>();
                fieldsMap.put("recAct", fields[6]);
                fieldsMap.put("amount", fields[3]);
                //fieldsMap.put("recName", fields[3]);
                fieldsMap.put("serialNum", fields[0]);
                fieldsMap.put("payState", fields[7]);
                fieldsMap.put("payInfo", fields[7] + "-" + fields[8]);
                String payState = fieldsMap.get("payState");
                if (!RET_CODE.equals(payState)) {
                    payState = PaymentState.FAIL_Payment;
                    fieldsMap.put("payState", payState);
                }
                result.put(fields[0], fieldsMap);
            }
        } else {
            for (int i = 0; i < rows.length; i++) {
                String row = rows[i];
                String[] fields = row.split("\\|", 100);
                Map<String, String> fieldsMap = new HashMap<String, String>();
                if (i == 0) {
                    fieldsMap.put("totalNum", fields[0]);
                    fieldsMap.put("totalAmt", fields[1]);
                    result.put("header", fieldsMap);
                } else {
                    //fieldsMap.put("orderNum", fields[0]);
                    fieldsMap.put("recAct", fields[1]);
                    fieldsMap.put("amount", fields[2]);
                    fieldsMap.put("recName", fields[3]);
                    fieldsMap.put("serialNum", fields[12]);
                    fieldsMap.put("payState", fields[13]);//根据中文判断:交易成功
                    fieldsMap.put("payInfo", fields[13]);
                    String payState = fieldsMap.get("payState");
                    if (!"交易成功".equals(payState)) {
                        payState = PaymentState.FAIL_Payment;
                        fieldsMap.put("payState", payState);
                    }
                    result.put(fields[0], fieldsMap);
                }
            }
        }
        return result;
    }

    /**
     * 根据ats批次号查询银行批次号和协议号
     *
     * @param REQSEQID
     * @param p_transDate
     * @param errMsg
     * @return
     */
    private List<String> getBankBatchNumAndBusiCode(String REQSEQID, Date p_transDate, StringBuilder errMsg) {
        List<String> result = new ArrayList<String>();
        if (FGBiz.dspCenter.dspSet.dbConnectionSet != null) {
            try {
                Connection dbConn = null;
                try {
                    dbConn = getDbConnection();
                    Map<String, Object> reqSeqIDMap = JDBCHelper.execQuerySingle(dbConn, "select BANKREQBATCHNO,BANKREQSEQID from REQSEQIDMAPPING where REQSEQID=?", new Object[]{REQSEQID});
                    if (reqSeqIDMap != null && reqSeqIDMap.size() > 0) {
                        result.add(String.valueOf(reqSeqIDMap.get("BANKREQSEQID")));//协议号
                        result.add(String.valueOf(reqSeqIDMap.get("BANKREQBATCHNO")));//批次号
                        return result;
                    }
                    errMsg.append("查询为空");
                } catch (Exception ex) {
                    errMsg.append(LogHelper.getStackTrace(ex));
                    ex.printStackTrace();
                } finally {
                    if (dbConn != null) {
                        dbConn.close();
                    }
                }
            } catch (Exception ex) {
                errMsg.append(LogHelper.getStackTrace(ex));
                ex.printStackTrace();
            }
        } else {
            errMsg.append("数据库连接未配置或有误");
        }
        return result;
    }

    /**
     * 手续费查询
     *
     * @param oriReqXml
     * @param reqRespHeader
     * @param errMsg
     * @return
     * @throws Exception
     */
    private Map<String, Map<String, String>> getPoundage(String oriReqXml, ReqRespHeader reqRespHeader, StringBuilder errMsg) throws Exception {
        WriteBankLogLn("手续费查询开始...");
        XmlTextReader xmlTextReader = new XmlTextReader(oriReqXml);
        ReqBatPayRec my_p_req1988 = new ReqBatPayRec(xmlTextReader, reqRespHeader);

        String seqNumberStart = getBankConfig().getMapValueByKey("Sys_Head", "CONSUMER_ID") + reqHeader.corporation;
        Map<String, Map<String, String>> poundAgeMap = new HashMap<String, Map<String, String>>();

        String busiType = getBankConfig().getMapValueByKey("ACROSSBANK", "BUSITYPE");
        String busiCode = getBankConfig().getMapValueByKey("ACROSSBANK", "BUSICODE");

        String payAccount = my_p_req1988.ownAct;//付款账户
        String accountType = getBankConfig().getMapValueByKey("ACCOUNT_TYPE", payAccount);//账户类型
        if (StringHelper.isNullOrEmpty(accountType)) {
            accountType = getBankConfig().getMapValueByKey("ACCOUNT_TYPE", "*");
        }

        List<ReqPayRecDetail> details = new ArrayList<ReqPayRecDetail>();
        while (my_p_req1988.readRecord()) {
            details.add(my_p_req1988.readedDetail);
        }

        if (details != null && details.size() > 0) {
            int totalNum = details.size();
            int pageSize = Integer.parseInt(getBankConfig().getMapValueByKey("ACROSSBANK", "FEEQUERYPAGESIZE"));
            int aliquotFlag = totalNum % pageSize;//整除标志
            int pageNum = 0;
            if (totalNum <= pageSize) {
                pageNum = 1;
                pageSize = totalNum;
                aliquotFlag = 0;
            } else {
                pageNum = totalNum / pageSize;
            }

            int currentNumber = 0;

            for (int i = 1; i <= pageNum; i++) {
                //赋值通用参数
                ZYB02Header bankHeader = new ZYB02Header();
                bankHeader.SEQ_NO = seqNumberStart + reqHeader.reqSeqID + SybUtil.getValidatecode(1) + i;
                bankHeader.TRAN_CODE = getBankConfig().getMapValueByKey("TRANS_CODE", "ACROSSBANKFEEQUERY");
                String transTime = my_p_req1988.reqHeader.transTime;
                bankHeader.TRAN_DATE = Format.Date10Format.format(DateHelper.convertToDateExtra(transTime));
                bankHeader.TRAN_TIMESTAMP = TIME12FORMAT.format(DateHelper.convertToDateExtra(transTime));
                bankHeader.USER_IP = getIpInfoMap(oriReqXml).get("userIP");
                bankHeader.SERVER_IP = getIpInfoMap(oriReqXml).get("serverIP");
                //发银行报文的XML对象
                XmlTextWriter xmlWriter = new XmlTextWriter();
                xmlWriter.autoFormat = false;
                //写入通用的头部节点
                writeCommon(xmlWriter, bankHeader);
                xmlWriter.writeElementString("AcctNo", payAccount);
                xmlWriter.writeElementString("AcctType", accountType);
                xmlWriter.writeElementString("SourceType", getBankConfig().getMapValueByKey("Sys_Head", "SOURCE_TYPE"));
                xmlWriter.writeElementString("BusiType", busiType);
                xmlWriter.writeElementString("BusiCode", busiCode);
                try {
                    xmlWriter.writeStartElement("List");
                    Map<String, String> serialNumMapping = new HashMap<String, String>();
                    for (int j = 1; j <= pageSize; j++) {
                        XElement row = new XElement("Map", "");
                        row.addChild(new XElement("SeqNo", StringHelper.valueOf(j - 1)));//序号
                        row.addChild(new XElement("TranAmt", details.get(currentNumber).payAmount));//交易金额
                        row.addChild(new XElement("TranCcy", "CNY"));//币种(CNY)

                        xmlWriter.writeXElement(row);
                        serialNumMapping.put(StringHelper.valueOf(j - 1), details.get(currentNumber).askNumber);
                        currentNumber++;
                    }

                    xmlWriter.writeEndElement();
                    xmlWriter.writeEndDocument();

                    String[] tmpStrRet = sendXmlToBank(xmlWriter.toXmlString());
                    feeQueryResponseDeal(tmpStrRet, poundAgeMap, serialNumMapping, errMsg);
                } catch (Exception e) {
                    errMsg.append("没有查询到手续费信息：" + e.getMessage());
                    return poundAgeMap;
                }
            }

            if (aliquotFlag > 0) {
                //赋值通用参数
                ZYB02Header bankHeader = new ZYB02Header();
                bankHeader.SEQ_NO = seqNumberStart + reqHeader.reqSeqID + SybUtil.getValidatecode(1) + (pageNum + 1);
                bankHeader.TRAN_CODE = getBankConfig().getMapValueByKey("TRANS_CODE", "ACROSSBANKFEEQUERY");
                String transTime = my_p_req1988.reqHeader.transTime;
                bankHeader.TRAN_DATE = Format.Date10Format.format(DateHelper.convertToDateExtra(transTime));
                bankHeader.TRAN_TIMESTAMP = TIME12FORMAT.format(DateHelper.convertToDateExtra(transTime));
                bankHeader.USER_IP = getIpInfoMap(oriReqXml).get("userIP");
                bankHeader.SERVER_IP = getIpInfoMap(oriReqXml).get("serverIP");
                //发银行报文的XML对象
                XmlTextWriter xmlWriter = new XmlTextWriter();
                xmlWriter.autoFormat = false;
                //写入通用的头部节点
                writeCommon(xmlWriter, bankHeader);
                xmlWriter.writeElementString("AcctNo", payAccount);
                xmlWriter.writeElementString("AcctType", accountType);
                xmlWriter.writeElementString("SourceType", getBankConfig().getMapValueByKey("Sys_Head", "SOURCE_TYPE"));
                xmlWriter.writeElementString("BusiType", busiType);
                xmlWriter.writeElementString("BusiCode", busiCode);
                try {
                    xmlWriter.writeStartElement("List");
                    Map<String, String> serialNumMapping = new HashMap<String, String>();
                    for (int k = 1; k <= aliquotFlag; k++) {
                        XElement row = new XElement("Map", "");
                        row.addChild(new XElement("SeqNo", StringHelper.valueOf(k - 1)));//序号
                        row.addChild(new XElement("TranAmt", details.get(currentNumber).payAmount));//交易金额
                        row.addChild(new XElement("TranCcy", "CNY"));//币种(CNY)
                        xmlWriter.writeXElement(row);
                        serialNumMapping.put(StringHelper.valueOf(k - 1), details.get(currentNumber).askNumber);
                        currentNumber++;
                    }
                    xmlWriter.writeEndElement();
                    xmlWriter.writeEndDocument();

                    String[] tmpStrRet = sendXmlToBank(xmlWriter.toXmlString());
                    feeQueryResponseDeal(tmpStrRet, poundAgeMap, serialNumMapping, errMsg);
                } catch (Exception e) {
                    errMsg.append("没有查询到手续费信息：" + e.getMessage());
                    return poundAgeMap;
                }
            }
        } else {
            errMsg.append("没有查询到手续费信息：DetailRecord标签为空");
        }
        WriteBankLogLn("手续费查询结束...");
        return poundAgeMap;
    }

    /**
     * 跨行批量手续费查询响应处理
     *
     * @param tmpStrRet
     * @param poundAgeMap
     * @param serialNumMapping
     * @param errMsg
     * @throws Exception
     */
    private void feeQueryResponseDeal(String[] tmpStrRet, Map<String, Map<String, String>> poundAgeMap, Map<String, String> serialNumMapping, StringBuilder errMsg) throws Exception {
        XmlTextReader tmpBkReader;
        if (tmpStrRet[0].length() == 0) {
            StringBuilder tmpSbMsg = new StringBuilder();
            tmpBkReader = loadBankRespXmlReader(tmpStrRet[1], tmpSbMsg);
            if (tmpBkReader != null) {
                String ret_code = tmpBkReader.getFirstText("/Message/Head/_RejCode");
                String ret_msg = tmpBkReader.getFirstText("/Message/Head/_RejMsg");
                if (RET_CODE.equals(ret_code)) {
                    while (tmpBkReader.read("/Message/Body/List/Map")) {
                        Map<String, String> feeInfoMap = new HashMap<String, String>();
                        String seq_no = tmpBkReader.readedXElement.getSingleText("SeqNo");
                        String chg_amt = tmpBkReader.readedXElement.getSingleText("ChgAmt");//实收金额
                        if (poundAgeMap.containsKey(serialNumMapping.get(seq_no))) {
                            String chg_amt_old = poundAgeMap.get(serialNumMapping.get(seq_no)).get("chg_amt");
                            String chg_amt_now = StringHelper.valueOf(Double.parseDouble(chg_amt_old) + Double.parseDouble(chg_amt));
                            feeInfoMap.put("chg_amt", chg_amt_now);
                            poundAgeMap.put(serialNumMapping.get(seq_no), feeInfoMap);
                        } else {
                            feeInfoMap.put("chg_amt", chg_amt);
                            poundAgeMap.put(serialNumMapping.get(seq_no), feeInfoMap);
                        }
                    }
                } else {
                    errMsg.append("没有查询到手续费信息：" + ret_code + "-" + ret_msg);
                }
            } else {
                errMsg.append("没有查询到手续费信息：" + tmpSbMsg.toString());
            }
        } else {
            errMsg.append("没有查询到手续费信息：" + tmpStrRet[1]);
        }
    }

    //<editor-fold desc="手续费查询方法备份20181126 20:00">
    /*private Map<String,Map<String,String>> getPoundage_back(String oriReqXml, ReqRespHeader reqRespHeader,StringBuilder errMsg) throws Exception {
        WriteBankLogLn("手续费查询开始...");
        XmlTextReader xmlTextReader = new XmlTextReader(oriReqXml);
        ReqBatPayRec my_p_req1988 = new ReqBatPayRec(xmlTextReader,reqRespHeader);

        String seqNumberStart = getBankConfig().getMapValueByKey("Sys_Head","CONSUMER_ID")+reqHeader.corporation;
        Map<String,Map<String,String>> poundAgeMap = new HashMap<>();

        String payAccount = my_p_req1988.ownAct;//付款账户
        String accountType = getBankConfig().getMapValueByKey("ACCOUNT_TYPE",payAccount);//账户类型
        if(StringHelper.isNullOrEmpty(accountType)) {
            accountType = getBankConfig().getMapValueByKey("ACCOUNT_TYPE","*");
        }
        //<editor-fold desc="分页查询">
        *//*int totalNum = Integer.parseInt(p_req1988.totalNum);
        int pageSize = Integer.parseInt(getBankConfig().getMapValueByKey("APP_HEAD","TOTAL_NUM"));
        int aliquotFlag = totalNum%pageSize;//整除标志
        int pageNum = 0;
        if(totalNum <= pageSize) {
            pageNum = 1;
            pageSize = totalNum;
        } else {
            pageNum = totalNum/pageSize;
        }

        for(int i = 1;i <= pageNum; i++) {
            for(int j = 1;j <= pageSize; j++) {

            }
        }

        if(aliquotFlag > 0) {
            for(int k = 1;k <= aliquotFlag; k++) {

            }
        }

        List<ReqPayRecDetail> reqPayRecDetails = new ArrayList<>();
        while (p_req1988.readRecord()) {
            reqPayRecDetails.add(p_req1988.readedDetail);
        }*//*
        //</editor-fold>
        try {
            //赋值通用参数
            ZYB02Header bankHeader = new ZYB02Header();
            bankHeader.SEQ_NO = seqNumberStart+reqHeader.transSeqID+SybUtil.getValidatecode(2);
            bankHeader.TRAN_CODE = getBankConfig().getMapValueByKey("TRANS_CODE", "ACROSSBANKFEEQUERY");
            String transTime = my_p_req1988.reqHeader.transTime;
            bankHeader.TRAN_DATE = Format.Date8Format.format(DateHelper.convertToDateExtra(transTime));
            bankHeader.TRAN_TIMESTAMP = Format.Time9Format.format(DateHelper.convertToDateExtra(transTime));
            //发银行报文的XML对象
            XmlTextWriter xmlWriter = new XmlTextWriter();
            xmlWriter.autoFormat = false;
            //写入通用的头部节点
            writeCommonHeader(xmlWriter, bankHeader);

            xmlWriter.writeElementString("ACCT_NO", payAccount);
            xmlWriter.writeElementString("ACCT_TYPE", accountType);
            *//*
                刘利锋(高二荣) 11-26 12:04:41
                走大小额的busi_type送A100,busi_code送0001
                刘利锋(高二荣) 11-26 12:05:04
                走超网的busi_type送C200，busi_code送SCCT

                D 小额(工作日小于等于5万，节假日小于等于50万)
                P 超网(小于等于5万)
                C 大额(金额没有限制，时间有限制)ats那边会调用AQ01OtherElse查询大额支付系统是否开启，这里不用管时间

                金额大于5万直接走大额系统C
                小于等于5万：加急-超网P,不加急-小额D
                *//*
            String trsMode = "";
            BigDecimal payAmount = new BigDecimal(my_p_req1988.readedDetail.payAmount);//这里有问题，这里还没去读取明细，readedDetail还是null
            if(payAmount.compareTo(maxAmout) == 1) {
                trsMode = "C";
            } else {
                if("1".equals(my_p_req1988.readedDetail.paySpd)) {//加急
                    trsMode = "P";
                } else {//不加急
                    trsMode = "D";
                }
            }
            String busi_type = "";
            String busi_code = "";
            if("C".equals(trsMode) || "D".equals(trsMode)) {//大小额
                busi_type = "A100";
                busi_code = "0001";
            } else {//超网
                busi_type = "C200";
                busi_code = "SCCT";
            }
            xmlWriter.writeElementString("BUSI_TYPE", busi_type);
            xmlWriter.writeElementString("BUSI_CODE", busi_code);
            xmlWriter.writeStartElement("CHARGE_BATCH");
            int serialNumber = 0;
            Map<String,String> serialNumMapping = new HashMap<>();
            while (my_p_req1988.readRecord()) {
                XElement row = new XElement("Row", "");
                row.addChild(new XElement("SEQ_NO", StringHelper.valueOf(serialNumber)));//序号
                row.addChild(new XElement("TRAN_AMT", my_p_req1988.readedDetail.payAmount));//交易金额
                row.addChild(new XElement("TRAN_CCY", "CNY"));//币种(CNY)
                xmlWriter.writeXElement(row);
                serialNumMapping.put(StringHelper.valueOf(serialNumber),my_p_req1988.readedDetail.askNumber);
                serialNumber++;
            }
            xmlWriter.writeEndElement();
            xmlWriter.writeEndDocument();

            String[] tmpStrRet = sendToBank(xmlWriter.toXmlString());
            XmlTextReader tmpBkReader;
            if (tmpStrRet[0].length() == 0) {
                StringBuilder tmpSbMsg = new StringBuilder();
                tmpBkReader = loadBankRespXmlReader(tmpStrRet[1], tmpSbMsg);
                if (tmpBkReader != null) {
                    *//** 解析响应报文获取手续费
     * <CHG_METHOD>T</CHG_METHOD>收费方式
     * <CHG_CCY>CNY</CHG_CCY>
     * <CHG_AMT>0.0</CHG_AMT>实收金额
     * <BASE_CHARGE_AMT>0.0</BASE_CHARGE_AMT>
     * <ORIG_TRAN_CCY>CNY</ORIG_TRAN_CCY>
     * <CHARGE_TYPE>W06</CHARGE_TYPE>费用类型
     * <ORIG_TRAN_AMT>4512.55</ORIG_TRAN_AMT>
     * <BASE_CHARGE_CCY>CNY</BASE_CHARGE_CCY>
     * <SEQ_NO>0</SEQ_NO>序号
     *//*
                    String ret_status = tmpBkReader.getFirstText("/Reply_Msg/Sys_Head/RET_STATUS");
                    String ret_code = tmpBkReader.getFirstText("/Reply_Msg/Sys_Head/RET_ARRAY/Row/RET_CODE");
                    String ret_msg = tmpBkReader.getFirstText("/Reply_Msg/Sys_Head/RET_ARRAY/Row/RET_MSG");
                    if(TMPSTATUS.equals(ret_status)) {
                        while (tmpBkReader.read("/Reply_Msg/Body/CHARGE_ARRAY/Row")) {
                            Map<String,String> feeInfoMap = new HashMap<>();
                            String seq_no = tmpBkReader.readedXElement.getSingleText("SEQ_NO");
                            String chg_amt = tmpBkReader.readedXElement.getSingleText("CHG_AMT");//实收金额
                            //String chg_method = tmpBkReader.readedXElement.getSingleText("CHG_METHOD");//收费方式
                            //String charge_type = tmpBkReader.readedXElement.getSingleText("CHARGE_TYPE");//费用类型
                            //feeInfoMap.put("chg_amt",chg_amt);
                            //feeInfoMap.put("chg_method",chg_method);
                            //feeInfoMap.put("charge_type",charge_type);
                            //poundAgeMap.put(serialNumMapping.get(seq_no),feeInfoMap);
                            if(poundAgeMap.containsKey(serialNumMapping.get(seq_no))) {
                                String chg_amt_old = poundAgeMap.get(serialNumMapping.get(seq_no)).get("chg_amt");
                                String chg_amt_now = StringHelper.valueOf(Double.parseDouble(chg_amt_old)+Double.parseDouble(chg_amt));
                                feeInfoMap.put("chg_amt",chg_amt_now);
                                poundAgeMap.put(serialNumMapping.get(seq_no),feeInfoMap);
                            } else {
                                feeInfoMap.put("chg_amt",chg_amt);
                                poundAgeMap.put(serialNumMapping.get(seq_no),feeInfoMap);
                            }
                        }
                        WriteBankLogLn("手续费查询结束...");
                    } else {
                        errMsg.append("没有查询到手续费信息："+ret_code+"-"+ret_msg);
                        //throw new Exception("没有查询到手续费信息："+ret_code+"-"+ret_msg);
                    }
                } else {
                    errMsg.append("没有查询到手续费信息："+tmpSbMsg.toString());
                    //throw new Exception("没有查询到手续费信息："+tmpSbMsg.toString());
                }
            } else {
                errMsg.append("没有查询到手续费信息："+tmpStrRet[1]);
                //throw new Exception("没有查询到手续费信息："+tmpStrRet[1]);
            }
        } catch (Exception e) {
            errMsg.append("没有查询到手续费信息："+e.getMessage());
            //throw new Exception("没有查询到手续费信息："+e.getMessage());
        }
        return poundAgeMap;
    }*/
    //</editor-fold>


    /**
     * 中原银行文件传输平台配置
     *
     * @return
     */
    public FtpClientConfig getConfig() {
        //String transCode = getBankConfig().getValueAsString("fileTransCode");
        String serverIp = getBankConfig().getValueAsString("fileTransServerIp");
        int port = Integer.parseInt(getBankConfig().getValueAsString("fileTransPort"));
        String clientIp = getBankConfig().getValueAsString("fileTransClientIp");
        String uid = getBankConfig().getValueAsString("fileTransUid");
        String password = getBankConfig().getValueAsString("fileTransPassword");
        int connectTimeOut = Integer.parseInt(getBankConfig().getValueAsString("fileTransConnectTimeout"));
        FtpClientConfig config = new FtpClientConfig();
        config.setServerIp(serverIp);
        config.setPort(port);
        config.setClientIp(clientIp);
        config.setUid(uid);
        config.setPasswd(password);
        config.setConnectTimeout(connectTimeOut);
        return config;
    }
}
